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
Nested ClassesModifier and TypeClassDescriptionstatic enum
The serialization can optionally include context information in addition to the feature structures.(package private) class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private final CasSerializerSupport
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private boolean
private boolean
private boolean
private boolean
private boolean
private com.fasterxml.jackson.core.JsonFactory
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private static final com.fasterxml.jackson.core.io.SerializedString
private String
private static final com.fasterxml.jackson.core.io.SerializedString
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) CasSerializerSupport
getCss()
static 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)
-
Field Details
-
CONTEXT_NAME
private static final com.fasterxml.jackson.core.io.SerializedString CONTEXT_NAME -
TYPE_SYSTEM_NAME
private static final com.fasterxml.jackson.core.io.SerializedString TYPE_SYSTEM_NAME -
TYPES_NAME
private static final com.fasterxml.jackson.core.io.SerializedString TYPES_NAME -
ID_NAME
private static final com.fasterxml.jackson.core.io.SerializedString ID_NAME -
SUB_TYPES_NAME
private static final com.fasterxml.jackson.core.io.SerializedString SUB_TYPES_NAME -
FEATURE_TYPES_NAME
private static final com.fasterxml.jackson.core.io.SerializedString FEATURE_TYPES_NAME -
FEATURE_REFS_NAME
private static final com.fasterxml.jackson.core.io.SerializedString FEATURE_REFS_NAME -
FEATURE_ARRAY_NAME
private static final com.fasterxml.jackson.core.io.SerializedString FEATURE_ARRAY_NAME -
FEATURE_BYTE_ARRAY_NAME
private static final com.fasterxml.jackson.core.io.SerializedString FEATURE_BYTE_ARRAY_NAME -
REFERENCED_FSS_NAME
private static final com.fasterxml.jackson.core.io.SerializedString REFERENCED_FSS_NAME -
VIEWS_NAME
private static final com.fasterxml.jackson.core.io.SerializedString VIEWS_NAME -
TYPE_NAME
private static final com.fasterxml.jackson.core.io.SerializedString TYPE_NAME -
COLLECTION_NAME
private static final com.fasterxml.jackson.core.io.SerializedString COLLECTION_NAME -
DELTA_CAS_NAME
private static final com.fasterxml.jackson.core.io.SerializedString DELTA_CAS_NAME -
ADDED_MEMBERS_NAME
private static final com.fasterxml.jackson.core.io.SerializedString ADDED_MEMBERS_NAME -
DELETED_MEMBERS_NAME
private static final com.fasterxml.jackson.core.io.SerializedString DELETED_MEMBERS_NAME -
REINDEXED_MEMBERS_NAME
private static final com.fasterxml.jackson.core.io.SerializedString REINDEXED_MEMBERS_NAME -
css
-
jsonFactory
private com.fasterxml.jackson.core.JsonFactory jsonFactory -
isDynamicEmbedding
private boolean isDynamicEmbedding -
isWithContext
private boolean isWithContext -
isWithSubtypes
private boolean isWithSubtypes -
isWithExpandedTypeNames
private boolean isWithExpandedTypeNames -
isOmit0Values
private boolean isOmit0Values -
typeSystemReference
-
-
Constructor Details
-
JsonCasSerializer
public JsonCasSerializer()Creates a new JsonCasSerializer
-
-
Method Details
-
getCss
CasSerializerSupport getCss() -
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
-