Class JSONWriter


  • public class JSONWriter
    extends SSSOMWriter
    A writer to serialise a SSSOM mapping set into a JSON format.

    The JSON format generated by this writer is not the JSON format used by SSSOM-Py! SSSOM-Py uses a JSON-LD format that, for now, is completely unspecified. Instead, this writer produces a “pure” JSON format that is merely a direct JSON rendering of the internal SSSOM data model.

    • Constructor Detail

      • JSONWriter

        public JSONWriter​(File file)
                   throws IOException
        Creates a new instance that will write data to the specified file.
        Parameters:
        file - The file to write the mapping set to.
        Throws:
        IOException - If the file cannot be opened for any reason.
      • JSONWriter

        public JSONWriter​(OutputStream stream)
        Creates a new instance that will write data to the specified stream.
        Parameters:
        stream - The stream to write the mapping set to.
      • JSONWriter

        public JSONWriter​(String filename)
                   throws IOException
        Creates a new instance that will write data to a file with the specified filename.
        Parameters:
        filename - The name of the file to write the mapping set to.
        Throws:
        IOException - If the file cannot be opened for any reason.
    • Method Detail

      • setShortenIRIs

        public void setShortenIRIs​(boolean shorten)
        Enables or disables shortening of identifiers. If enabled, all identifiers will be written as CURIEs and a curie_map will be included in the output.
        Parameters:
        shorten - True to enable shortening of all identifiers. It is disabled by default.
      • setWriteCurieMapInContext

        public void setWriteCurieMapInContext​(boolean enabled)
        Enables writing the curie map in a JSON-LD-like "@context" object.

        SSSOM-Py expects the prefix names to be declared in the @context dictionary, so this option enables that behaviour. Note that it only has effect is shortening of IRIs (see setShortenIRIs(boolean)) is also enabled, because there is no curie map to write otherwise.

        Parameters:
        enabled - True to write the curie map as a @context dictionary. The default is to write it as a normal curie_map slot.
      • doWrite

        protected void doWrite​(MappingSet mappingSet)
                        throws IOException
        Serialises a mapping set into the underlying file.
        Specified by:
        doWrite in class SSSOMWriter
        Parameters:
        mappingSet - The mapping set to serialise.
        Throws:
        IOException - If an I/O error occurs.