Class JsonCasSerializer
CAS serializer for JSON formats.
Writes a CAS in a JSON format.
To use,
- create an instance of this class,
- (optionally) configure the instance, and then
- call serialize on the instance, optionally passing in additional parameters.
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:
- (S) The CAS to serialize
- (S) where to put the output - an OutputStream, Writer, or File
- (I,S) a type system - (default null) if supplied, it is used to "filter" types and features that are serialized. If provided, only those that exist in the passed in type system are included in the serialization
- (I,S) a flag for prettyprinting - default false (no prettyprinting)
For Json serialization, additional configuration from the Jackson implementation can be configured
on 2 associated Jackson instances:- JsonFactory
- JsonGenerator
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The serialization can optionally include context information in addition to the feature structures. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
jsonSerialize
(CAS aCAS, Object output) Serializes a CAS using JSONstatic 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 a Cas to an Output, using configurations set on this instance.void
serialize
(CAS cas, Object output, XmiSerializationSharedData sharedData, Marker marker) void
serialize
(CAS cas, 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, JsonContentHandlerJacksonWrapper jch, XmiSerializationSharedData sharedData, Marker marker) set an error handler to receive information about errorspass in a type system to use for filtering what gets serialized; only those types and features which are defined this type system are included.sets which Json context format to use when serializingsetJsonFactory
(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 instancesetOmit0Values
(boolean omitDefaultValues) setPrettyPrint
(boolean pp) set or reset the pretty print flag (default is false)Sets static embedding modesetTypeSystemReference
(String reference)
-
Constructor Details
-
JsonCasSerializer
public JsonCasSerializer()Creates a new JsonCasSerializer
-
-
Method Details
-
jsonSerialize
Serializes a CAS using JSON- Parameters:
aCAS
- CAS to serialize.output
- a File, OutputStream or Writer to which to write the XMI document- Throws:
IOException
- if there was an IOException
-
jsonSerialize
public static void jsonSerialize(CAS aCAS, TypeSystem aTargetTypeSystem, Object output) throws IOException Serializes a CAS to an output (File, OutputStream, XMI stream, or Writer). The supplied typesystem filters the output- Parameters:
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 document- Throws:
IOException
- if there was an IOException
-
serialize
Serialize a Cas to an Output, using configurations set on this instance. Constructs a JsonContentHandlerJacksonWrapper, using configured JsonFactory and prettyprint settings if any- Parameters:
cas
- - the CAS to serializeoutput
- - where the output goes, an OutputStream, Writer, or File- Throws:
IOException
- if there was an IOException
-
serialize
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)- Parameters:
cas
- The CAS to serializejch
- the configured content handler- Throws:
IOException
- if there was an IOException
-
setPrettyPrint
set or reset the pretty print flag (default is false)- Parameters:
pp
- true to do pretty printing of output- Returns:
- the original instance, possibly updated
-
setJsonFactory
set which JsonFactory instance to use; if null, a new instance is used this can be used to preconfigure the JsonFactory instance- Parameters:
jsonFactory
- -- Returns:
- the original instance, possibly updated
-
setFilterTypes
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.- Parameters:
ts
- the filter- Returns:
- the original instance, possibly updated
-
setTypeSystemReference
-
setErrorHandler
set an error handler to receive information about errors- Parameters:
eh
- the error handler- Returns:
- the original instance, possibly updated
-
setStaticEmbedding
Sets static embedding mode- Returns:
- the original instance, possibly updated
-
setJsonContext
sets which Json context format to use when serializing- Parameters:
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 already- Returns:
- the original instance, possibly updated
-
setOmit0Values
-