Class JsonSerializer
java.lang.Object
org.wikidata.wdtk.datamodel.helpers.JsonSerializer
- All Implemented Interfaces:
EntityDocumentDumpProcessor,EntityDocumentProcessor
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final com.fasterxml.jackson.databind.ObjectMapperObject mapper that is used to serialize JSON. -
Constructor Summary
ConstructorsConstructorDescriptionJsonSerializer(OutputStream outputStream) Creates a new JSON serializer that writes its output to the given stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Finishes the processing by performing any final steps, such as closing resources.intReturns the number of entity documents serialized so far.static StringgetJsonString(EntityDocument entityDocument) Serializes the given object in JSON and returns the resulting string.static StringgetJsonString(EntityUpdate update) Serializes the given object in JSON and returns the resulting string.static StringgetJsonString(ItemDocument itemDocument) Serializes the given object in JSON and returns the resulting string.static StringgetJsonString(MediaInfoDocument mediaInfoDocument) Serializes the given object in JSON and returns the resulting string.static StringgetJsonString(PropertyDocument propertyDocument) Serializes the given object in JSON and returns the resulting string.static StringgetJsonString(Statement statement) Serializes the given object in JSON and returns the resulting string.voidopen()Starts the processing by performing any initial steps to prepare processing.voidprocessItemDocument(ItemDocument itemDocument) Processes the given ItemDocument.voidprocessLexemeDocument(LexemeDocument lexemeDocument) Processes the given LexemeDocument.voidprocessMediaInfoDocument(MediaInfoDocument mediaInfoDocument) Processes the given MediaInfoDocument.voidprocessPropertyDocument(PropertyDocument propertyDocument) Processes the given PropertyDocument.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.wikidata.wdtk.datamodel.interfaces.EntityDocumentProcessor
processEntityRedirectDocument
-
Field Details
-
mapper
protected static final com.fasterxml.jackson.databind.ObjectMapper mapperObject mapper that is used to serialize JSON.
-
-
Constructor Details
-
JsonSerializer
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 whenclose()is call ed.- Parameters:
outputStream- the output stream to write to
-
-
Method Details
-
open
public void open()Description copied from interface:EntityDocumentDumpProcessorStarts the processing by performing any initial steps to prepare processing.- Specified by:
openin interfaceEntityDocumentDumpProcessor
-
processItemDocument
Description copied from interface:EntityDocumentProcessorProcesses the given ItemDocument.- Specified by:
processItemDocumentin interfaceEntityDocumentProcessor- Parameters:
itemDocument- the ItemDocument
-
processPropertyDocument
Description copied from interface:EntityDocumentProcessorProcesses the given PropertyDocument.- Specified by:
processPropertyDocumentin interfaceEntityDocumentProcessor- Parameters:
propertyDocument- the PropertyDocument
-
processLexemeDocument
Description copied from interface:EntityDocumentProcessorProcesses the given LexemeDocument.- Specified by:
processLexemeDocumentin interfaceEntityDocumentProcessor- Parameters:
lexemeDocument- the LexemeDocument
-
processMediaInfoDocument
Description copied from interface:EntityDocumentProcessorProcesses the given MediaInfoDocument.- Specified by:
processMediaInfoDocumentin interfaceEntityDocumentProcessor- Parameters:
mediaInfoDocument- the MediaInfoDocument
-
close
public void close()Description copied from interface:EntityDocumentDumpProcessorFinishes the processing by performing any final steps, such as closing resources.- Specified by:
closein interfaceEntityDocumentDumpProcessor
-
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
-