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.CasDocSerializercdsprivate booleanindexIdprivate booleanisEmbeddedprivate booleanisEmbeddedFromFsFeatureprivate booleanisOmitDefaultValuesprivate booleanisWithContextprivate booleanisWithSubtypesprivate JsonContentHandlerJacksonWrapperjchprivate com.fasterxml.jackson.core.JsonGeneratorjgprivate intlastEncodedTypeCodeprivate JsonCasSerializer.MapType2SubtypesmapType2Subtypesprivate java.util.List<TypeImpl>parentTypesWithNoInstancesprivate java.util.Map<java.lang.String,com.fasterxml.jackson.core.io.SerializedString>serializedStringsprivate booleanstartedFeatureTypesprivate booleanstartedReferencedFSsprivate java.util.Map<java.lang.String,XmlElementName>usedTypeName2XmlElementName
-
Constructor Summary
Constructors Modifier Constructor Description privateJsonDocSerializer(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 voidaddJsonFeatContext(TypeImpl type)_feature_types : { "featName" : "_ref" or "_byte_array, ...private voidaddJsonSubtypes(TypeImpl ti)Add subtype information for used types limited to used subtypesprotected voidaddNameSpace(XmlElementName xmlElementName)Called to generate a new namespace prefix and add it to this element - due to a collisionprotected voidcheckForNameCollision(XmlElementName xmlElementName)private voidcollectUsedSubtypes()private com.fasterxml.jackson.core.io.SerializedStringfeatureTypeLabel(int fsClass)Return null or a string representing the type of the featureprivate com.fasterxml.jackson.core.io.SerializedStringgetSerializedString(java.lang.String s)private com.fasterxml.jackson.core.io.SerializedStringgetSerializedTypeName(TypeImpl ti)private com.fasterxml.jackson.core.io.SerializedStringgetShortFeatureName(FeatureImpl feat)protected voidinitializeNamespaces()private booleanisDynamicOrStaticMultiRef(FeatureImpl fi, TOP fs)private booleanisDynamicOrStaticMultiRef(FeatureImpl fi, TOP fs, boolean isListAsFSs)private voidmaybeDoStartFeatureTypes()private voidmaybeWriteTypeFeat(TypeImpl ti)private voidserializeJsonLdContext()JSON: serialize context infoprivate java.util.List<TOP>[]sortByViewType()protected XmlElementNameuimaTypeName2XmiElementName(java.lang.String uimaTypeName)Converts a UIMA-style dotted type name to the element name that should be used in the serialization.private voidwriteArray(TOP fs, FeatureImpl fi, int featureClass)private voidwriteArrayElements(int size, IntConsumer_withIOException ic)protected voidwriteArrays(TOP fs, int typeCode, int typeClass)Write FSArraysprivate voidwriteEmbeddedFs(TOP fs)protected voidwriteEndOfIndividualFs()protected voidwriteEndOfSerialization()protected voidwriteFeatureStructures(int elementCount)protected voidwriteFs(TOP fs, int typeCode)private voidwriteFSArray(TOP array, int array_size)private voidwriteFsOrLists(TOP fs, TypeImpl ti, boolean isListAsFSs)private voidwriteFsOrRef(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 voidwriteFsOrRef(TOP fs, FeatureImpl fi)protected voidwriteFsRef(TOP fs)protected booleanwriteFsStart(TOP fs, int typeCode)private voidwriteJsonArrayValues(TOP array, int arrayType)private voidwriteJsonListValues(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 voidwriteList(TOP fs, FeatureImpl fi, int featureClass, boolean isListAsFSs)protected voidwriteListsAsIndividualFSs(TOP fs, int typeCode)private voidwriteNumeric(FeatureImpl fi, long v)protected voidwriteView(Sofa sofa, java.util.Collection<TOP> members)protected voidwriteView(Sofa sofa, java.util.Collection<TOP> added, java.util.Collection<TOP> deleted, java.util.Collection<TOP> reindexed)private voidwriteViewForDeltas(com.fasterxml.jackson.core.io.SerializedString kind, java.util.Collection<TOP> deltaMembers)private voidwriteViewMembers(java.util.Collection<TOP> members)private voidwriteViewMembers(java.util.List<java.lang.String> members)protected voidwriteViews()
-
-
-
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:
initializeNamespacesin classCasSerializerSupport.CasSerializerSupportSerialize
-
writeViews
protected void writeViews() throws java.lang.Exception- Specified by:
writeViewsin classCasSerializerSupport.CasSerializerSupportSerialize- Throws:
java.lang.Exception
-
writeFeatureStructures
protected void writeFeatureStructures(int elementCount) throws java.lang.Exception- Specified by:
writeFeatureStructuresin classCasSerializerSupport.CasSerializerSupportSerialize- Throws:
java.lang.Exception
-
writeEndOfSerialization
protected void writeEndOfSerialization() throws java.io.IOException- Specified by:
writeEndOfSerializationin 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:
writeViewin 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:
writeViewin 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.IOExceptionJSON: 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:
checkForNameCollisionin classCasSerializerSupport.CasSerializerSupportSerialize
-
writeFsStart
protected boolean writeFsStart(TOP fs, int typeCode) throws java.io.IOException
- Specified by:
writeFsStartin 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:
writeFsRefin 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:
writeFsin classCasSerializerSupport.CasSerializerSupportSerialize- Throws:
java.io.IOException
-
writeListsAsIndividualFSs
protected void writeListsAsIndividualFSs(TOP fs, int typeCode) throws java.io.IOException
- Specified by:
writeListsAsIndividualFSsin 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:
writeArraysin classCasSerializerSupport.CasSerializerSupportSerialize- Throws:
java.io.IOException
-
writeEndOfIndividualFs
protected void writeEndOfIndividualFs() throws java.io.IOException- Specified by:
writeEndOfIndividualFsin 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.NumberFormatExceptionjava.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:
uimaTypeName2XmiElementNamein 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:
addNameSpacein classCasSerializerSupport.CasSerializerSupportSerialize- Parameters:
xmlElementName-
-
isDynamicOrStaticMultiRef
private boolean isDynamicOrStaticMultiRef(FeatureImpl fi, TOP fs)
-
isDynamicOrStaticMultiRef
private boolean isDynamicOrStaticMultiRef(FeatureImpl fi, TOP fs, boolean isListAsFSs)
-
-