public class JsonSerializer extends Object implements EntityDocumentDumpProcessor
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.
To generate the correct official JSON serialization used by Wikidata,
serialized entity documents must be based on the Jackson implementations,
i.e., be instances of JacksonItemDocument or
JacksonPropertyDocument. The serializer checks is this is the case
and converts the data if not. If the caller can provide data based on Jackson
objects or has the choice of generating data in this format (e.g., if
documents are converted for filtering purposes anyway), then this will
improve performance since no conversion is needed there.
| Modifier and Type | Field and Description |
|---|---|
protected DatamodelConverter |
datamodelConverter
Object used to convert given entity documents to Jackson implementations
for serialization whenever needed.
|
protected int |
entityDocumentCount
Counter for the number of documents serialized so far.
|
protected com.fasterxml.jackson.databind.ObjectMapper |
mapper
Object mapper that is used to serialize JSON.
|
protected OutputStream |
outputStream
The stream that the resulting JSON is written to.
|
| Constructor and Description |
|---|
JsonSerializer(OutputStream outputStream)
Creates a new JSON serializer that writes its output to the given stream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Finishes the processing by performing any final steps, such as closing
resources.
|
int |
getEntityDocumentCount()
Returns the number of entity documents serialized so far.
|
void |
open()
Starts the processing by performing any initial steps to prepare
processing.
|
void |
processItemDocument(ItemDocument itemDocument)
Processes the given ItemDocument.
|
void |
processPropertyDocument(PropertyDocument propertyDocument)
Processes the given PropertyDocument.
|
protected void |
reportException(Exception e)
Reports a given exception as a RuntimeException, since the interface does
not allow us to throw checked exceptions directly.
|
protected void |
serializeEntityDocument(EntityDocument entityDocument)
Writes the JSON serialization of the given
EntityDocument. |
protected final OutputStream outputStream
protected final DatamodelConverter datamodelConverter
protected final com.fasterxml.jackson.databind.ObjectMapper mapper
protected int entityDocumentCount
public JsonSerializer(OutputStream outputStream)
close() is call ed.outputStream - the output stream to write topublic void open()
EntityDocumentDumpProcessoropen in interface EntityDocumentDumpProcessorpublic void processItemDocument(ItemDocument itemDocument)
EntityDocumentProcessorprocessItemDocument in interface EntityDocumentProcessoritemDocument - the ItemDocumentpublic void processPropertyDocument(PropertyDocument propertyDocument)
EntityDocumentProcessorprocessPropertyDocument in interface EntityDocumentProcessorpropertyDocument - the PropertyDocumentpublic void close()
EntityDocumentDumpProcessorclose in interface EntityDocumentDumpProcessorpublic int getEntityDocumentCount()
protected void reportException(Exception e)
e - the exception to reportRuntimeException - in all casesprotected void serializeEntityDocument(EntityDocument entityDocument)
EntityDocument.entityDocument - the document to serializeCopyright © 2014–2015 Wikidata Toolkit Developers. Generated from source code published under the Apache License 2.0. For more information, see the Wikidata Toolkit homepage