Package org.apache.uima.json
Class JsonCasSerializer.JsonDocSerializer
java.lang.Object
org.apache.uima.cas.impl.CasSerializerSupport.CasSerializerSupportSerialize
org.apache.uima.json.JsonCasSerializer.JsonDocSerializer
- Enclosing class:
JsonCasSerializer
class JsonCasSerializer.JsonDocSerializer
extends CasSerializerSupport.CasSerializerSupportSerialize
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CasSerializerSupport.CasDocSerializer
private boolean
private boolean
private boolean
private final boolean
private final boolean
private final boolean
private final JsonContentHandlerJacksonWrapper
private final com.fasterxml.jackson.core.JsonGenerator
private int
private final JsonCasSerializer.MapType2Subtypes
private boolean
private boolean
private final Map
<String, XmlElementName> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
JsonDocSerializer
(ContentHandler ch, CASImpl cas, XmiSerializationSharedData sharedData, MarkerImpl marker) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addJsonFeatContext
(TypeImpl type) _feature_types : { "featName" : "_ref" or "_byte_array, ...private void
Add subtype information for used types limited to used subtypesprotected void
addNameSpace
(XmlElementName xmlElementName) Called to generate a new namespace prefix and add it to this element - due to a collisionprotected void
checkForNameCollision
(XmlElementName xmlElementName) private void
private com.fasterxml.jackson.core.io.SerializedString
featureTypeLabel
(int fsClass) Return null or a string representing the type of the featureprivate com.fasterxml.jackson.core.io.SerializedString
private com.fasterxml.jackson.core.io.SerializedString
private com.fasterxml.jackson.core.io.SerializedString
protected void
private boolean
isDynamicOrStaticMultiRef
(FeatureImpl fi, TOP fs) private boolean
isDynamicOrStaticMultiRef
(FeatureImpl fi, TOP fs, boolean isListAsFSs) private void
private void
private void
JSON: serialize context infoprotected XmlElementName
uimaTypeName2XmiElementName
(String uimaTypeName) Converts a UIMA-style dotted type name to the element name that should be used in the serialization.private void
writeArray
(TOP fs, FeatureImpl fi, int featureClass) private void
writeArrayElements
(int size, IntConsumer_withIOException ic) protected void
writeArrays
(TOP fs, int typeCode, int typeClass) Write FSArraysprivate void
writeEmbeddedFs
(TOP fs) protected void
protected void
protected void
writeFeatureStructures
(int elementCount) protected void
private void
writeFSArray
(TOP array, int array_size) private void
writeFsOrLists
(TOP fs, TypeImpl ti, boolean isListAsFSs) private void
writeFsOrRef
(TOP fs) for arrays and lists, recursively write one FS, as actual FS, if dynamic embedding and single ref OR, just write the reference id If trying to write the null FS (due to filtering for instance), write 0private void
writeFsOrRef
(TOP fs, FeatureImpl fi) protected void
writeFsRef
(TOP fs) protected boolean
writeFsStart
(TOP fs, int typeCode) private void
writeJsonArrayValues
(TOP array, int arrayType) private void
writeJsonListValues
(TOP curNode) Only called if no sharing of list nodes exists (except for non-dynamic case) Only called for list nodes referred to by Feature value slots in some FS.private void
writeList
(TOP fs, FeatureImpl fi, int featureClass, boolean isListAsFSs) protected void
writeListsAsIndividualFSs
(TOP fs, int typeCode) private void
writeNumeric
(FeatureImpl fi, long v) protected void
writeView
(Sofa sofa, Collection<TOP> members) protected void
writeView
(Sofa sofa, Collection<TOP> added, Collection<TOP> deleted, Collection<TOP> reindexed) private void
writeViewForDeltas
(com.fasterxml.jackson.core.io.SerializedString kind, Collection<TOP> deltaMembers) private void
writeViewMembers
(Collection<TOP> members) private void
writeViewMembers
(List<String> members) protected void
-
Field Details
-
cds
-
jch
-
jg
private final com.fasterxml.jackson.core.JsonGenerator jg -
serializedStrings
-
usedTypeName2XmlElementName
-
mapType2Subtypes
-
parentTypesWithNoInstances
-
lastEncodedTypeCode
private int lastEncodedTypeCode -
startedReferencedFSs
private boolean startedReferencedFSs -
isOmitDefaultValues
private final boolean isOmitDefaultValues -
isWithContext
private final boolean isWithContext -
isWithSubtypes
private final boolean isWithSubtypes -
indexId
private boolean indexId -
isEmbedded
private boolean isEmbedded -
isEmbeddedFromFsFeature
private boolean isEmbeddedFromFsFeature -
startedFeatureTypes
private boolean startedFeatureTypes
-
-
Constructor Details
-
Method Details
-
initializeNamespaces
protected void initializeNamespaces()- Specified by:
initializeNamespaces
in classCasSerializerSupport.CasSerializerSupportSerialize
-
writeViews
- Specified by:
writeViews
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
Exception
-
writeFeatureStructures
- Specified by:
writeFeatureStructures
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
Exception
-
writeEndOfSerialization
- Specified by:
writeEndOfSerialization
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
IOException
-
sortByViewType
- Returns:
- the List
[] returned by cds.indexedFSs, but with each view sorted by type
-
writeView
- Specified by:
writeView
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
IOException
-
writeViewForDeltas
private void writeViewForDeltas(com.fasterxml.jackson.core.io.SerializedString kind, Collection<TOP> deltaMembers) throws IOException - Throws:
IOException
-
writeView
protected void writeView(Sofa sofa, Collection<TOP> added, Collection<TOP> deleted, Collection<TOP> reindexed) throws IOException - Specified by:
writeView
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
IOException
-
writeViewMembers
- Throws:
IOException
-
writeViewMembers
- Throws:
IOException
-
serializeJsonLdContext
JSON: serialize context info
The context has several parts.
The typeSystemReference is an optional URI to a type system that is written out.
The types part is organized by the type hierarchy, starting with the uima.cas.TOP type. There is an entry for each type which has 1 or more serailized instances, and also for all supertypes of those types. The entry is a JSON key-value pair "short-type-name" : {...}.
The information for each type has 3 sections:
- _subtypes - a JSON map of key-value pairs, keyed by the short type-name of used subtypes of this type. If this type has no used subtypes, this element is omitted. The value is an instance of this structure, for that type.
- _id - the fully qualified UIMA type name
- @featureTypes - a map with keys being specific features of the type that need extra information about their contents, and the value being that extra information.
- "@featureByteArray" - indicates the string value should be decoded as a base64 binary encoded byte array
- "{ "@featureRef" : "short_type_name" } - indicates the number or array of numbers should be interpreted as a reference to a FS having this number (or array of numbers) as its id(s). 0 is interpreted as a null reference. The type of the FS being referred to is of type "short_type_name" or a subtype.
- Throws:
IOException
-
addJsonFeatContext
_feature_types : { "featName" : "_ref" or "_byte_array, ... }- Parameters:
type
- the type for which to generate the feature context info- Throws:
IOException
-
maybeDoStartFeatureTypes
- Throws:
IOException
-
getShortFeatureName
-
addJsonSubtypes
Add subtype information for used types limited to used subtypes- Throws:
IOException
-
collectUsedSubtypes
private void collectUsedSubtypes() -
getSerializedTypeName
-
getSerializedString
-
checkForNameCollision
- Specified by:
checkForNameCollision
in classCasSerializerSupport.CasSerializerSupportSerialize
-
writeFsStart
- Specified by:
writeFsStart
in classCasSerializerSupport.CasSerializerSupportSerialize
- Parameters:
fs
- -typeCode
- -- Returns:
- true if writing out referenced items (JSON)
- Throws:
IOException
-
writeFsRef
- Specified by:
writeFsRef
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
Exception
-
maybeWriteTypeFeat
- Throws:
IOException
-
writeFs
- Specified by:
writeFs
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
IOException
-
writeListsAsIndividualFSs
- Specified by:
writeListsAsIndividualFSs
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
IOException
-
writeFsOrLists
- Throws:
IOException
-
writeNumeric
- Throws:
IOException
-
writeArray
- Throws:
IOException
-
writeList
private void writeList(TOP fs, FeatureImpl fi, int featureClass, boolean isListAsFSs) throws IOException - Throws:
IOException
-
writeFsOrRef
for arrays and lists, recursively write one FS, as actual FS, if dynamic embedding and single ref OR, just write the reference id If trying to write the null FS (due to filtering for instance), write 0- Parameters:
addr
-- Throws:
IOException
-
writeEmbeddedFs
- Throws:
IOException
-
writeFsOrRef
- Throws:
IOException
-
writeArrays
Write FSArrays- Specified by:
writeArrays
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
IOException
-
writeEndOfIndividualFs
- Specified by:
writeEndOfIndividualFs
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
IOException
-
writeJsonArrayValues
- Throws:
IOException
-
writeArrayElements
- Throws:
IOException
-
writeFSArray
- Throws:
NumberFormatException
IOException
-
writeJsonListValues
Only called if no sharing of list nodes exists (except for non-dynamic case) Only called for list nodes referred to by Feature value slots in some FS.- Parameters:
curNode
- the address of the start of the list- Throws:
IOException
-
featureTypeLabel
private com.fasterxml.jackson.core.io.SerializedString featureTypeLabel(int fsClass) Return null or a string representing the type of the feature- Parameters:
fsClass
- the class of the featurefeatCode
- the feature code- Returns:
- _ref, _array, _byte_array, or null
-
uimaTypeName2XmiElementName
Converts a UIMA-style dotted type name to the element name that should be used in the serialization. The XMI element name consists of three parts - the Namespace URI, the Local Name, and the QName (qualified name).- Specified by:
uimaTypeName2XmiElementName
in classCasSerializerSupport.CasSerializerSupportSerialize
- Parameters:
uimaTypeName
- a UIMA-style dotted type name- Returns:
- a data structure holding the three components of the XML element name
-
addNameSpace
Called to generate a new namespace prefix and add it to this element - due to a collision- Specified by:
addNameSpace
in classCasSerializerSupport.CasSerializerSupportSerialize
- Parameters:
xmlElementName
-
-
isDynamicOrStaticMultiRef
-
isDynamicOrStaticMultiRef
-