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
Modifier and TypeFieldDescriptionprotected static final com.fasterxml.jackson.databind.ObjectMapper
Object mapper that is used to serialize JSON. -
Constructor Summary
ConstructorDescriptionJsonSerializer
(OutputStream outputStream) Creates a new JSON serializer that writes its output to the given stream. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Finishes the processing by performing any final steps, such as closing resources.int
Returns the number of entity documents serialized so far.static String
getJsonString
(EntityDocument entityDocument) Serializes the given object in JSON and returns the resulting string.static String
getJsonString
(EntityUpdate update) Serializes the given object in JSON and returns the resulting string.static String
getJsonString
(ItemDocument itemDocument) Serializes the given object in JSON and returns the resulting string.static String
getJsonString
(MediaInfoDocument mediaInfoDocument) Serializes the given object in JSON and returns the resulting string.static String
getJsonString
(PropertyDocument propertyDocument) Serializes the given object in JSON and returns the resulting string.static String
getJsonString
(Statement statement) Serializes the given object in JSON and returns the resulting string.void
open()
Starts the processing by performing any initial steps to prepare processing.void
processItemDocument
(ItemDocument itemDocument) Processes the given ItemDocument.void
processLexemeDocument
(LexemeDocument lexemeDocument) Processes the given LexemeDocument.void
processMediaInfoDocument
(MediaInfoDocument mediaInfoDocument) Processes the given MediaInfoDocument.void
processPropertyDocument
(PropertyDocument propertyDocument) Processes the given PropertyDocument.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:EntityDocumentDumpProcessor
Starts the processing by performing any initial steps to prepare processing.- Specified by:
open
in interfaceEntityDocumentDumpProcessor
-
processItemDocument
Description copied from interface:EntityDocumentProcessor
Processes the given ItemDocument.- Specified by:
processItemDocument
in interfaceEntityDocumentProcessor
- Parameters:
itemDocument
- the ItemDocument
-
processPropertyDocument
Description copied from interface:EntityDocumentProcessor
Processes the given PropertyDocument.- Specified by:
processPropertyDocument
in interfaceEntityDocumentProcessor
- Parameters:
propertyDocument
- the PropertyDocument
-
processLexemeDocument
Description copied from interface:EntityDocumentProcessor
Processes the given LexemeDocument.- Specified by:
processLexemeDocument
in interfaceEntityDocumentProcessor
- Parameters:
lexemeDocument
- the LexemeDocument
-
processMediaInfoDocument
Description copied from interface:EntityDocumentProcessor
Processes the given MediaInfoDocument.- Specified by:
processMediaInfoDocument
in interfaceEntityDocumentProcessor
- 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 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
-