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
Fields Modifier and Type Field Description private CasSerializerSupport.CasDocSerializer
cds
private boolean
indexId
private boolean
isEmbedded
private boolean
isEmbeddedFromFsFeature
private boolean
isOmitDefaultValues
private boolean
isWithContext
private boolean
isWithSubtypes
private JsonContentHandlerJacksonWrapper
jch
private com.fasterxml.jackson.core.JsonGenerator
jg
private int
lastEncodedTypeCode
private JsonCasSerializer.MapType2Subtypes
mapType2Subtypes
private java.util.List<TypeImpl>
parentTypesWithNoInstances
private java.util.Map<java.lang.String,com.fasterxml.jackson.core.io.SerializedString>
serializedStrings
private boolean
startedFeatureTypes
private boolean
startedReferencedFSs
private java.util.Map<java.lang.String,XmlElementName>
usedTypeName2XmlElementName
-
Constructor Summary
Constructors Modifier Constructor Description private
JsonDocSerializer(org.xml.sax.ContentHandler ch, CASImpl cas, XmiSerializationSharedData sharedData, MarkerImpl marker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addJsonFeatContext(TypeImpl type)
_feature_types : { "featName" : "_ref" or "_byte_array, ...private void
addJsonSubtypes(TypeImpl ti)
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
collectUsedSubtypes()
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
getSerializedString(java.lang.String s)
private com.fasterxml.jackson.core.io.SerializedString
getSerializedTypeName(TypeImpl ti)
private com.fasterxml.jackson.core.io.SerializedString
getShortFeatureName(FeatureImpl feat)
protected void
initializeNamespaces()
private boolean
isDynamicOrStaticMultiRef(FeatureImpl fi, TOP fs)
private boolean
isDynamicOrStaticMultiRef(FeatureImpl fi, TOP fs, boolean isListAsFSs)
private void
maybeDoStartFeatureTypes()
private void
maybeWriteTypeFeat(TypeImpl ti)
private void
serializeJsonLdContext()
JSON: serialize context infoprivate java.util.List<TOP>[]
sortByViewType()
protected XmlElementName
uimaTypeName2XmiElementName(java.lang.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
writeEndOfIndividualFs()
protected void
writeEndOfSerialization()
protected void
writeFeatureStructures(int elementCount)
protected void
writeFs(TOP fs, int typeCode)
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, java.util.Collection<TOP> members)
protected void
writeView(Sofa sofa, java.util.Collection<TOP> added, java.util.Collection<TOP> deleted, java.util.Collection<TOP> reindexed)
private void
writeViewForDeltas(com.fasterxml.jackson.core.io.SerializedString kind, java.util.Collection<TOP> deltaMembers)
private void
writeViewMembers(java.util.Collection<TOP> members)
private void
writeViewMembers(java.util.List<java.lang.String> members)
protected void
writeViews()
-
-
-
Field Detail
-
cds
private final CasSerializerSupport.CasDocSerializer cds
-
jch
private final JsonContentHandlerJacksonWrapper jch
-
jg
private final com.fasterxml.jackson.core.JsonGenerator jg
-
serializedStrings
private final java.util.Map<java.lang.String,com.fasterxml.jackson.core.io.SerializedString> serializedStrings
-
usedTypeName2XmlElementName
private final java.util.Map<java.lang.String,XmlElementName> usedTypeName2XmlElementName
-
mapType2Subtypes
private final JsonCasSerializer.MapType2Subtypes mapType2Subtypes
-
parentTypesWithNoInstances
private final java.util.List<TypeImpl> 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 Detail
-
JsonDocSerializer
private JsonDocSerializer(org.xml.sax.ContentHandler ch, CASImpl cas, XmiSerializationSharedData sharedData, MarkerImpl marker)
-
-
Method Detail
-
initializeNamespaces
protected void initializeNamespaces()
- Specified by:
initializeNamespaces
in classCasSerializerSupport.CasSerializerSupportSerialize
-
writeViews
protected void writeViews() throws java.lang.Exception
- Specified by:
writeViews
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.lang.Exception
-
writeFeatureStructures
protected void writeFeatureStructures(int elementCount) throws java.lang.Exception
- Specified by:
writeFeatureStructures
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.lang.Exception
-
writeEndOfSerialization
protected void writeEndOfSerialization() throws java.io.IOException
- Specified by:
writeEndOfSerialization
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.io.IOException
-
sortByViewType
private java.util.List<TOP>[] sortByViewType()
- Returns:
- the List
[] returned by cds.indexedFSs, but with each view sorted by type
-
writeView
protected void writeView(Sofa sofa, java.util.Collection<TOP> members) throws java.io.IOException
- Specified by:
writeView
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.io.IOException
-
writeViewForDeltas
private void writeViewForDeltas(com.fasterxml.jackson.core.io.SerializedString kind, java.util.Collection<TOP> deltaMembers) throws java.io.IOException
- Throws:
java.io.IOException
-
writeView
protected void writeView(Sofa sofa, java.util.Collection<TOP> added, java.util.Collection<TOP> deleted, java.util.Collection<TOP> reindexed) throws java.io.IOException
- Specified by:
writeView
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.io.IOException
-
writeViewMembers
private void writeViewMembers(java.util.Collection<TOP> members) throws java.io.IOException
- Throws:
java.io.IOException
-
writeViewMembers
private void writeViewMembers(java.util.List<java.lang.String> members) throws java.io.IOException
- Throws:
java.io.IOException
-
serializeJsonLdContext
private void serializeJsonLdContext() throws java.io.IOException
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:
java.io.IOException
-
addJsonFeatContext
private void addJsonFeatContext(TypeImpl type) throws java.io.IOException
_feature_types : { "featName" : "_ref" or "_byte_array, ... }- Parameters:
type
- the type for which to generate the feature context info- Throws:
java.io.IOException
-
maybeDoStartFeatureTypes
private void maybeDoStartFeatureTypes() throws java.io.IOException
- Throws:
java.io.IOException
-
getShortFeatureName
private com.fasterxml.jackson.core.io.SerializedString getShortFeatureName(FeatureImpl feat)
-
addJsonSubtypes
private void addJsonSubtypes(TypeImpl ti) throws java.io.IOException
Add subtype information for used types limited to used subtypes- Throws:
java.io.IOException
-
collectUsedSubtypes
private void collectUsedSubtypes()
-
getSerializedTypeName
private com.fasterxml.jackson.core.io.SerializedString getSerializedTypeName(TypeImpl ti)
-
getSerializedString
private com.fasterxml.jackson.core.io.SerializedString getSerializedString(java.lang.String s)
-
checkForNameCollision
protected void checkForNameCollision(XmlElementName xmlElementName)
- Specified by:
checkForNameCollision
in classCasSerializerSupport.CasSerializerSupportSerialize
-
writeFsStart
protected boolean writeFsStart(TOP fs, int typeCode) throws java.io.IOException
- Specified by:
writeFsStart
in classCasSerializerSupport.CasSerializerSupportSerialize
- Parameters:
fs
- -typeCode
- -- Returns:
- true if writing out referenced items (JSON)
- Throws:
java.io.IOException
-
writeFsRef
protected void writeFsRef(TOP fs) throws java.lang.Exception
- Specified by:
writeFsRef
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.lang.Exception
-
maybeWriteTypeFeat
private void maybeWriteTypeFeat(TypeImpl ti) throws java.io.IOException
- Throws:
java.io.IOException
-
writeFs
protected void writeFs(TOP fs, int typeCode) throws java.io.IOException
- Specified by:
writeFs
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.io.IOException
-
writeListsAsIndividualFSs
protected void writeListsAsIndividualFSs(TOP fs, int typeCode) throws java.io.IOException
- Specified by:
writeListsAsIndividualFSs
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.io.IOException
-
writeFsOrLists
private void writeFsOrLists(TOP fs, TypeImpl ti, boolean isListAsFSs) throws java.io.IOException
- Throws:
java.io.IOException
-
writeNumeric
private void writeNumeric(FeatureImpl fi, long v) throws java.io.IOException
- Throws:
java.io.IOException
-
writeArray
private void writeArray(TOP fs, FeatureImpl fi, int featureClass) throws java.io.IOException
- Throws:
java.io.IOException
-
writeList
private void writeList(TOP fs, FeatureImpl fi, int featureClass, boolean isListAsFSs) throws java.io.IOException
- Throws:
java.io.IOException
-
writeFsOrRef
private void writeFsOrRef(TOP fs) throws java.io.IOException
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:
java.io.IOException
-
writeEmbeddedFs
private void writeEmbeddedFs(TOP fs) throws java.io.IOException
- Throws:
java.io.IOException
-
writeFsOrRef
private void writeFsOrRef(TOP fs, FeatureImpl fi) throws java.io.IOException
- Throws:
java.io.IOException
-
writeArrays
protected void writeArrays(TOP fs, int typeCode, int typeClass) throws java.io.IOException
Write FSArrays- Specified by:
writeArrays
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.io.IOException
-
writeEndOfIndividualFs
protected void writeEndOfIndividualFs() throws java.io.IOException
- Specified by:
writeEndOfIndividualFs
in classCasSerializerSupport.CasSerializerSupportSerialize
- Throws:
java.io.IOException
-
writeJsonArrayValues
private void writeJsonArrayValues(TOP array, int arrayType) throws java.io.IOException
- Throws:
java.io.IOException
-
writeArrayElements
private void writeArrayElements(int size, IntConsumer_withIOException ic) throws java.io.IOException
- Throws:
java.io.IOException
-
writeFSArray
private void writeFSArray(TOP array, int array_size) throws java.lang.NumberFormatException, java.io.IOException
- Throws:
java.lang.NumberFormatException
java.io.IOException
-
writeJsonListValues
private void writeJsonListValues(TOP curNode) throws java.io.IOException
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:
java.io.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
protected XmlElementName uimaTypeName2XmiElementName(java.lang.String uimaTypeName)
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
protected void addNameSpace(XmlElementName xmlElementName)
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
private boolean isDynamicOrStaticMultiRef(FeatureImpl fi, TOP fs)
-
isDynamicOrStaticMultiRef
private boolean isDynamicOrStaticMultiRef(FeatureImpl fi, TOP fs, boolean isListAsFSs)
-
-