public class JsonCasSerializer extends Object
Writes a CAS in a JSON format.
To use,
After the 1st 2 steps, the serializer instance may be used for multiple calls (on multiple threads) to the 3rd serialize step, if all calls use the same configuration.
There are "convenience" static serialize methods that do these three steps for common configurations.
Parameters can be configured in this instance (I), and/or as part of the serialize(S) call.
The parameters that can be configured are:
For Json serialization, additional configuration from the Jackson implementation can be configured
on 2 associated Jackson instances:These 2 Jackson objects are settable/gettable from an instance of this class. They are created if not supplied by the caller.
Once this instance is configured, the serialize method is called to serialized a CAS to an output.
Instances of this class must be used on only one thread while configuration is being done; afterwards, multiple threads may use the configured instance, to call serialize.
Modifier and Type | Class and Description |
---|---|
static class |
JsonCasSerializer.JsonContextFormat
The serialization can optionally include context information in addition to the feature structures.
|
Constructor and Description |
---|
JsonCasSerializer()
Creates a new JsonCasSerializer
|
Modifier and Type | Method and Description |
---|---|
static void |
jsonSerialize(CAS aCAS,
Object output)
Serializes a CAS using JSON
|
static void |
jsonSerialize(CAS aCAS,
TypeSystem aTargetTypeSystem,
Object output)
Serializes a CAS to an output (File, OutputStream, XMI stream, or Writer).
|
static void |
jsonSerialize(CAS aCAS,
TypeSystem aTargetTypeSystem,
Object output,
boolean aPrettyPrint,
Marker aMarker,
XmiSerializationSharedData sharedData)
Serializes a Delta CAS to an output (File, Writer, or OutputStream).
|
void |
serialize(CAS cas,
org.apache.uima.json.impl.JsonContentHandlerJacksonWrapper jch)
Serialize a Cas to an Output configured in the passed in JsonContentHandlerJacksonWrapper
Constructs a new CasDocSerializer instance to do the serialization,
configured using this class's Delta marker setting (if any)
|
void |
serialize(CAS cas,
org.apache.uima.json.impl.JsonContentHandlerJacksonWrapper jch,
XmiSerializationSharedData sharedData,
Marker marker) |
void |
serialize(CAS cas,
Object output)
Serialize a Cas to an Output, using configurations set on this instance.
|
void |
serialize(CAS cas,
Object output,
XmiSerializationSharedData sharedData,
Marker marker) |
JsonCasSerializer |
setErrorHandler(ErrorHandler eh)
set an error handler to receive information about errors
|
JsonCasSerializer |
setFilterTypes(org.apache.uima.cas.impl.TypeSystemImpl ts)
pass in a type system to use for filtering what gets serialized;
only those types and features which are defined this type system are included.
|
JsonCasSerializer |
setJsonContext(JsonCasSerializer.JsonContextFormat format)
sets which Json context format to use when serializing
|
JsonCasSerializer |
setJsonFactory(com.fasterxml.jackson.core.JsonFactory jsonFactory)
set which JsonFactory instance to use; if null, a new instance is used
this can be used to preconfigure the JsonFactory instance
|
JsonCasSerializer |
setOmit0Values(boolean omitDefaultValues) |
JsonCasSerializer |
setPrettyPrint(boolean pp)
set or reset the pretty print flag (default is false)
|
JsonCasSerializer |
setStaticEmbedding()
Sets static embedding mode
|
JsonCasSerializer |
setTypeSystemReference(String reference) |
public static void jsonSerialize(CAS aCAS, Object output) throws IOException
aCAS
- CAS to serialize.output
- a File, OutputStream or Writer to which to write the XMI documentIOException
- if there was an IOExceptionpublic static void jsonSerialize(CAS aCAS, TypeSystem aTargetTypeSystem, Object output) throws IOException
aCAS
- CAS to serialize.aTargetTypeSystem
- type system used for filtering what gets serialized. Any types or features not in the
target type system will not be serialized. A null value indicates no filtering, that is,
that all types and features will be serialized.output
- output (File, OutputStream, or Writer) to which to write the JSON documentIOException
- if there was an IOExceptionpublic static void jsonSerialize(CAS aCAS, TypeSystem aTargetTypeSystem, Object output, boolean aPrettyPrint, Marker aMarker, XmiSerializationSharedData sharedData) throws IOException
aCAS
- CAS to serialize.aTargetTypeSystem
- type system to which the produced XMI will conform. Any types or features not in the
target type system will not be serialized. A null value indicates that all types and features
will be serialized.output
- File, Writer, or OutputStream to which to write the JSON documentaPrettyPrint
- if true the JSON output will be formatted with newlines and indenting. If false it will be unformatted.aMarker
- an optional object used to determine which FeatureStructures and modifications were created after
the mark was set. Used to serialize a Delta CAS consisting of only new FSs and views and
preexisting FSs and Views that have been modified. If null, full serialization is done.
See the JavaDocs for Marker
for details.sharedData
- optional, used for delta serialization (not yet supported)IOException
- if there was an IOExceptionpublic void serialize(CAS cas, Object output) throws IOException
cas
- - the CAS to serializeoutput
- - where the output goes, an OutputStream, Writer, or FileIOException
- if there was an IOExceptionpublic void serialize(CAS cas, Object output, XmiSerializationSharedData sharedData, Marker marker) throws IOException
IOException
public void serialize(CAS cas, org.apache.uima.json.impl.JsonContentHandlerJacksonWrapper jch) throws IOException
cas
- The CAS to serializejch
- the configured content handlerIOException
- if there was an IOExceptionpublic void serialize(CAS cas, org.apache.uima.json.impl.JsonContentHandlerJacksonWrapper jch, XmiSerializationSharedData sharedData, Marker marker) throws IOException
IOException
public JsonCasSerializer setPrettyPrint(boolean pp)
pp
- true to do pretty printing of outputpublic JsonCasSerializer setJsonFactory(com.fasterxml.jackson.core.JsonFactory jsonFactory)
jsonFactory
- -public JsonCasSerializer setFilterTypes(org.apache.uima.cas.impl.TypeSystemImpl ts)
ts
- the filterpublic JsonCasSerializer setTypeSystemReference(String reference)
public JsonCasSerializer setErrorHandler(ErrorHandler eh)
eh
- the error handlerpublic JsonCasSerializer setStaticEmbedding()
public JsonCasSerializer setJsonContext(JsonCasSerializer.JsonContextFormat format)
format
- the format to use for the serialization
Specifying the context flag also specifies all 3 subflags
Specifying one of the subflags as true sets the context flag to true if it isn't alreadypublic JsonCasSerializer setOmit0Values(boolean omitDefaultValues)
Copyright © 2006–2017 The Apache Software Foundation. All rights reserved.