Package com.fasterxml.jackson.core
Class JsonStreamContext
- java.lang.Object
-
- com.fasterxml.jackson.core.JsonStreamContext
-
- Direct Known Subclasses:
JsonReadContext,JsonWriteContext,TokenBufferReadContext,TokenFilterContext
public abstract class JsonStreamContext extends java.lang.ObjectShared base class for streaming processing contexts used during reading and writing of Json content using Streaming API. This context is also exposed to applications: context object can be used by applications to get an idea of relative position of the parser/generator within json content being processed. This allows for some contextual processing: for example, output within Array context can differ from that of Object context.
-
-
Field Summary
Fields Modifier and Type Field Description static intTYPE_ARRAYIndicator for "Array" context.static intTYPE_OBJECTIndicator for "Object" context.static intTYPE_ROOTIndicator for "Root Value" context (has not parent)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intgetCurrentIndex()abstract java.lang.StringgetCurrentName()Method for accessing name associated with the current location.java.lang.ObjectgetCurrentValue()Method for accessing currently active value being used by data-binding (as the source of streaming data to write, or destination of data being read), at this level in hierarchy.intgetEntryCount()intgetNestingDepth()The nesting depth is a count of objects and arrays that have not been closed, `{` and `[` respectively.abstract JsonStreamContextgetParent()Accessor for finding parent context of this context; will return null for root context.JsonLocationgetStartLocation(java.lang.Object srcRef)Deprecated.Since 2.13 usestartLocation(com.fasterxml.jackson.core.io.ContentReference)insteadjava.lang.StringgetTypeDesc()Deprecated.Since 2.8 usetypeDesc()insteadbooleanhasCurrentIndex()Method that may be called to verify whether this context has valid index: will return `false` before the first entry of Object context or before first element of Array context; otherwise returns `true`.booleanhasCurrentName()booleanhasPathSegment()Method that may be called to check if this context is either: Object, with at least one entry written (partially or completely) Array, with at least one entry written (partially or completely) and if so, return `true`; otherwise return `false`.booleaninArray()Method that returns true if this context is an Array context; that is, content is being read from or written to a JSON Array.booleaninObject()Method that returns true if this context is an Object context; that is, content is being read from or written to a JSON Object.booleaninRoot()Method that returns true if this context is a Root context; that is, content is being read from or written to without enclosing array or object structure.JsonPointerpathAsPointer()Factory method for constructing aJsonPointerthat points to the current location within the stream that this context is for, excluding information about "root context" (only relevant for multi-root-value cases)JsonPointerpathAsPointer(boolean includeRoot)Factory method for constructing aJsonPointerthat points to the current location within the stream that this context is for, optionally including "root value index"voidsetCurrentValue(java.lang.Object v)Method to call to pass value to be returned viagetCurrentValue(); typically called indirectly throughJsonParser.setCurrentValue(java.lang.Object)orJsonGenerator.setCurrentValue(java.lang.Object)).JsonLocationstartLocation(ContentReference srcRef)Optional method that may be used to access starting location of this context: for example, in case of JSON `Object` context, offset at which `[` token was read or written.java.lang.StringtoString()Overridden to provide developer readable "JsonPath" representation of the context.java.lang.StringtypeDesc()Method for accessing simple type description of current context; either ROOT (for root-level values), OBJECT (for field names and values of JSON Objects) or ARRAY (for values of JSON Arrays)
-
-
-
Field Detail
-
TYPE_ROOT
public static final int TYPE_ROOT
Indicator for "Root Value" context (has not parent)- See Also:
- Constant Field Values
-
TYPE_ARRAY
public static final int TYPE_ARRAY
Indicator for "Array" context.- See Also:
- Constant Field Values
-
TYPE_OBJECT
public static final int TYPE_OBJECT
Indicator for "Object" context.- See Also:
- Constant Field Values
-
-
Method Detail
-
getParent
public abstract JsonStreamContext getParent()
Accessor for finding parent context of this context; will return null for root context.- Returns:
- Parent context of this context, if any;
nullfor Root contexts
-
inArray
public final boolean inArray()
Method that returns true if this context is an Array context; that is, content is being read from or written to a JSON Array.- Returns:
Trueif this context represents an Array;falseotherwise
-
inRoot
public final boolean inRoot()
Method that returns true if this context is a Root context; that is, content is being read from or written to without enclosing array or object structure.- Returns:
Trueif this context represents a sequence of Root values;falseotherwise
-
inObject
public final boolean inObject()
Method that returns true if this context is an Object context; that is, content is being read from or written to a JSON Object.- Returns:
Trueif this context represents an Object;falseotherwise
-
getNestingDepth
public final int getNestingDepth()
The nesting depth is a count of objects and arrays that have not been closed, `{` and `[` respectively.- Returns:
- Nesting depth
- Since:
- 2.15
-
getTypeDesc
@Deprecated public final java.lang.String getTypeDesc()
Deprecated.Since 2.8 usetypeDesc()instead- Returns:
- Type description String
-
typeDesc
public java.lang.String typeDesc()
Method for accessing simple type description of current context; either ROOT (for root-level values), OBJECT (for field names and values of JSON Objects) or ARRAY (for values of JSON Arrays)- Returns:
- Type description String
- Since:
- 2.8
-
getEntryCount
public final int getEntryCount()
- Returns:
- Number of entries that are complete and started.
-
getCurrentIndex
public final int getCurrentIndex()
- Returns:
- Index of the currently processed entry, if any
-
hasCurrentIndex
public boolean hasCurrentIndex()
Method that may be called to verify whether this context has valid index: will return `false` before the first entry of Object context or before first element of Array context; otherwise returns `true`.- Returns:
Trueif this context has value index to access,falseotherwise- Since:
- 2.9
-
hasPathSegment
public boolean hasPathSegment()
Method that may be called to check if this context is either:- Object, with at least one entry written (partially or completely)
- Array, with at least one entry written (partially or completely)
Method is mostly used to determine whether this context should be used for constructing
JsonPointer- Returns:
Trueif this context has value path segment to access,falseotherwise- Since:
- 2.9
-
getCurrentName
public abstract java.lang.String getCurrentName()
Method for accessing name associated with the current location. Non-null forFIELD_NAMEand value events that directly follow field names; null for root level and array values.- Returns:
- Current field name within context, if any;
nullif none
-
hasCurrentName
public boolean hasCurrentName()
- Returns:
Trueif a call togetCurrentName()would return non-nullname;falseotherwise- Since:
- 2.9
-
getCurrentValue
public java.lang.Object getCurrentValue()
Method for accessing currently active value being used by data-binding (as the source of streaming data to write, or destination of data being read), at this level in hierarchy.Note that "current value" is NOT populated (or used) by Streaming parser or generator; it is only used by higher-level data-binding functionality. The reason it is included here is that it can be stored and accessed hierarchically, and gets passed through data-binding.
- Returns:
- Currently active value, if one has been assigned.
- Since:
- 2.5
-
setCurrentValue
public void setCurrentValue(java.lang.Object v)
Method to call to pass value to be returned viagetCurrentValue(); typically called indirectly throughJsonParser.setCurrentValue(java.lang.Object)orJsonGenerator.setCurrentValue(java.lang.Object)).- Parameters:
v- Current value to assign to this context- Since:
- 2.5
-
pathAsPointer
public JsonPointer pathAsPointer()
Factory method for constructing aJsonPointerthat points to the current location within the stream that this context is for, excluding information about "root context" (only relevant for multi-root-value cases)- Returns:
- Pointer instance constructed
- Since:
- 2.9
-
pathAsPointer
public JsonPointer pathAsPointer(boolean includeRoot)
Factory method for constructing aJsonPointerthat points to the current location within the stream that this context is for, optionally including "root value index"- Parameters:
includeRoot- Whether root-value offset is included as the first segment or not;- Returns:
- Pointer instance constructed
- Since:
- 2.9
-
startLocation
public JsonLocation startLocation(ContentReference srcRef)
Optional method that may be used to access starting location of this context: for example, in case of JSON `Object` context, offset at which `[` token was read or written. Often used for error reporting purposes. Implementations that do not keep track of such location are expected to returnJsonLocation.NA; this is what the default implementation does.- Parameters:
srcRef- Source reference needed to construct location instance- Returns:
- Location pointing to the point where the context
start marker was found (or written); never
null. - Since:
- 2.13
-
getStartLocation
@Deprecated public JsonLocation getStartLocation(java.lang.Object srcRef)
Deprecated.Since 2.13 usestartLocation(com.fasterxml.jackson.core.io.ContentReference)instead- Parameters:
srcRef- Source reference needed to construct location instance- Returns:
- Location pointing to the point where the context
start marker was found (or written); never
null. - Since:
- 2.9
-
toString
public java.lang.String toString()
Overridden to provide developer readable "JsonPath" representation of the context.- Overrides:
toStringin classjava.lang.Object- Returns:
- Simple developer-readable description this context layer
(note: NOT constructed with parents, unlike
pathAsPointer()) - Since:
- 2.9
-
-