Class JsonSerializer

java.lang.Object
org.wikidata.wdtk.datamodel.helpers.JsonSerializer
All Implemented Interfaces:
EntityDocumentDumpProcessor, EntityDocumentProcessor

public class JsonSerializer extends Object implements EntityDocumentDumpProcessor
This class implements EntityDocumentDumpProcessor to provide a serializer for EntityDocument objects in JSON.

The implementation does not check if open() has been called before the first document is serialized. It is the responsibility of the caller to do this.

Implementations of the data model are expected to be appropriately serializable to JSON with Jackson.

Author:
Markus Kroetzsch
  • Field Details

    • mapper

      protected static final com.fasterxml.jackson.databind.ObjectMapper mapper
      Object mapper that is used to serialize JSON.
  • Constructor Details

    • JsonSerializer

      public JsonSerializer(OutputStream outputStream)
      Creates a new JSON serializer that writes its output to the given stream. The output stream will be managed by the object, i.e., it will be closed when close() is call ed.
      Parameters:
      outputStream - the output stream to write to
  • Method Details

    • open

      public void open()
      Description copied from interface: EntityDocumentDumpProcessor
      Starts the processing by performing any initial steps to prepare processing.
      Specified by:
      open in interface EntityDocumentDumpProcessor
    • processItemDocument

      public void processItemDocument(ItemDocument itemDocument)
      Description copied from interface: EntityDocumentProcessor
      Processes the given ItemDocument.
      Specified by:
      processItemDocument in interface EntityDocumentProcessor
      Parameters:
      itemDocument - the ItemDocument
    • processPropertyDocument

      public void processPropertyDocument(PropertyDocument propertyDocument)
      Description copied from interface: EntityDocumentProcessor
      Processes the given PropertyDocument.
      Specified by:
      processPropertyDocument in interface EntityDocumentProcessor
      Parameters:
      propertyDocument - the PropertyDocument
    • processLexemeDocument

      public void processLexemeDocument(LexemeDocument lexemeDocument)
      Description copied from interface: EntityDocumentProcessor
      Processes the given LexemeDocument.
      Specified by:
      processLexemeDocument in interface EntityDocumentProcessor
      Parameters:
      lexemeDocument - the LexemeDocument
    • processMediaInfoDocument

      public void processMediaInfoDocument(MediaInfoDocument mediaInfoDocument)
      Description copied from interface: EntityDocumentProcessor
      Processes the given MediaInfoDocument.
      Specified by:
      processMediaInfoDocument in interface EntityDocumentProcessor
      Parameters:
      mediaInfoDocument - the MediaInfoDocument
    • close

      public void close()
      Description copied from interface: EntityDocumentDumpProcessor
      Finishes the processing by performing any final steps, such as closing resources.
      Specified by:
      close in interface EntityDocumentDumpProcessor
    • getEntityDocumentCount

      public int getEntityDocumentCount()
      Returns the number of entity documents serialized so far.
      Returns:
      number of serialized entity documents
    • getJsonString

      public static String getJsonString(EntityDocument entityDocument) throws com.fasterxml.jackson.core.JsonProcessingException
      Serializes the given object in JSON and returns the resulting string. Throws if the serialization fails.
      Parameters:
      entityDocument - object to serialize
      Returns:
      JSON serialization
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the object cannot be serialized
    • getJsonString

      public static String getJsonString(ItemDocument itemDocument) throws com.fasterxml.jackson.core.JsonProcessingException
      Serializes the given object in JSON and returns the resulting string. Throws if the serialization fails.
      Parameters:
      itemDocument - object to serialize
      Returns:
      JSON serialization
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the object cannot be serialized
    • getJsonString

      public static String getJsonString(PropertyDocument propertyDocument) throws com.fasterxml.jackson.core.JsonProcessingException
      Serializes the given object in JSON and returns the resulting string. Throws if the serialization fails.
      Parameters:
      propertyDocument - object to serialize
      Returns:
      JSON serialization
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the object cannot be serialized
    • getJsonString

      public static String getJsonString(MediaInfoDocument mediaInfoDocument) throws com.fasterxml.jackson.core.JsonProcessingException
      Serializes the given object in JSON and returns the resulting string. Throws if the serialization fails.
      Parameters:
      mediaInfoDocument - object to serialize
      Returns:
      JSON serialization
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the object cannot be serialized
    • getJsonString

      public static String getJsonString(Statement statement) throws com.fasterxml.jackson.core.JsonProcessingException
      Serializes the given object in JSON and returns the resulting string. Throws if the serialization fails.
      Parameters:
      statement - object to serialize
      Returns:
      JSON serialization
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the object cannot be serialized
    • getJsonString

      public static String getJsonString(EntityUpdate update) throws com.fasterxml.jackson.core.JsonProcessingException
      Serializes the given object in JSON and returns the resulting string. Throws if the serialization fails.
      Parameters:
      update - object to serialize
      Returns:
      JSON serialization
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the object cannot be serialized