Top Description Fields Constructors Methods
com.fasterxml.jackson.core

public abstract Class JsonStreamContext

extends Object
Class Inheritance
Known Direct Subclasses
com.fasterxml.jackson.core.filter.TokenFilterContext, com.fasterxml.jackson.core.json.JsonReadContext, com.fasterxml.jackson.core.json.JsonWriteContext
Imports
com.fasterxml.jackson.core.io.CharTypes, .ContentReference

Shared 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

Modifier and TypeField and Description
protected int
_index

Index of the currently processed entry.

protected int
_nestingDepth

The nesting depth is a count of objects and arrays that have not been closed, `{` and `[` respectively.

protected int
_type

Indicates logical type of context as one of TYPE_xxx constants.

public static final int
TYPE_ARRAY

Indicator for "Array" context.

public static final int
TYPE_OBJECT

Indicator for "Object" context.

public static final int
TYPE_ROOT

Indicator for "Root Value" context (has not parent)

Constructor Summary

AccessConstructor and Description
protected
protected
JsonStreamContext(JsonStreamContext
Context instance to copy type and index from
base
)

Copy constructor used by sub-classes for creating copies for buffering.

protected
JsonStreamContext(int type, int index)

Method Summary

Modifier and TypeMethod and Description
public final int

Returns:

Index of the currently processed entry, if any
getCurrentIndex
()

public abstract String

Returns:

Current field name within context, if any; null if none
getCurrentName
()

Method for accessing name associated with the current location.

public Object

Returns:

Currently active value, if one has been assigned.
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.

public final int

Returns:

Number of entries that are complete and started.
getEntryCount
()

public final int

Returns:

Nesting depth
getNestingDepth
()

The nesting depth is a count of objects and arrays that have not been closed, `{` and `[` respectively.

public abstract JsonStreamContext

Returns:

Parent context of this context, if any; null for Root contexts
getParent
()

Accessor for finding parent context of this context; will return null for root context.

public JsonLocation

Returns:

Location pointing to the point where the context start marker was found (or written); never null.
getStartLocation
(Object
Source reference needed to construct location instance
srcRef
)
Deprecated Since 2.13 use startLocation instead

public final String

Returns:

Type description String
getTypeDesc
()
Deprecated Since 2.8 use typeDesc instead

public boolean

Returns:

True if this context has value index to access, false otherwise
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`.

public boolean

Returns:

True if a call to getCurrentName() would return non-null name; false otherwise
hasCurrentName
()

public boolean

Returns:

True if this context has value path segment to access, false otherwise
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)
public final boolean

Returns:

True if this context represents an Array; false otherwise
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.

public final boolean

Returns:

True if this context represents an Object; false otherwise
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.

public final boolean

Returns:

True if this context represents a sequence of Root values; false otherwise
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.

public JsonPointer

Returns:

Pointer instance constructed
pathAsPointer
()

Factory method for constructing a JsonPointer that 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)

public JsonPointer

Returns:

Pointer instance constructed
pathAsPointer
(boolean
Whether root-value offset is included as the first segment or not;
includeRoot
)

Factory method for constructing a JsonPointer that points to the current location within the stream that this context is for, optionally including "root value index"

public void
setCurrentValue(Object
Current value to assign to this context
v
)

Method to call to pass value to be returned via getCurrentValue; typically called indirectly through JsonParser#setCurrentValue or JsonGenerator#setCurrentValue).

public JsonLocation

Returns:

Location pointing to the point where the context start marker was found (or written); never null.
startLocation
(ContentReference
Source reference needed to construct location instance
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.

public String

Returns:

Simple developer-readable description this context layer (note: NOT constructed with parents, unlike pathAsPointer)
toString
()

Overrides java.lang.Object.toString.

Overridden to provide developer readable "JsonPath" representation of the context.

public String

Returns:

Type description 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)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_indexback to summary
protected int _index

Index of the currently processed entry. Starts with -1 to signal that no entries have been started, and gets advanced each time a new entry is started, either by encountering an expected separator, or with new values if no separators are expected (the case for root context).

_nestingDepthback to summary
protected int _nestingDepth

The nesting depth is a count of objects and arrays that have not been closed, `{` and `[` respectively.

Since
2.15
_typeback to summary
protected int _type

Indicates logical type of context as one of TYPE_xxx constants.

TYPE_ARRAYback to summary
public static final int TYPE_ARRAY

Indicator for "Array" context.

TYPE_OBJECTback to summary
public static final int TYPE_OBJECT

Indicator for "Object" context.

TYPE_ROOTback to summary
public static final int TYPE_ROOT

Indicator for "Root Value" context (has not parent)

Constructor Detail

JsonStreamContextback to summary
protected JsonStreamContext()
JsonStreamContextback to summary
protected JsonStreamContext(JsonStreamContext base)

Copy constructor used by sub-classes for creating copies for buffering.

Parameters
base:JsonStreamContext

Context instance to copy type and index from

Since
2.9
JsonStreamContextback to summary
protected JsonStreamContext(int type, int index)

Method Detail

getCurrentIndexback to summary
public final int getCurrentIndex()
Returns:int

Index of the currently processed entry, if any

getCurrentNameback to summary
public abstract String getCurrentName()

Method for accessing name associated with the current location. Non-null for FIELD_NAME and value events that directly follow field names; null for root level and array values.

Returns:String

Current field name within context, if any; null if none

getCurrentValueback to summary
public 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:Object

Currently active value, if one has been assigned.

Since
2.5
getEntryCountback to summary
public final int getEntryCount()
Returns:int

Number of entries that are complete and started.

getNestingDepthback to summary
public final int getNestingDepth()

The nesting depth is a count of objects and arrays that have not been closed, `{` and `[` respectively.

Returns:int

Nesting depth

Since
2.15
getParentback to summary
public abstract JsonStreamContext getParent()

Accessor for finding parent context of this context; will return null for root context.

Returns:JsonStreamContext

Parent context of this context, if any; null for Root contexts

getStartLocationback to summary
public JsonLocation getStartLocation(Object srcRef)

Deprecated

Since 2.13 use startLocation instead

Parameters
srcRef:Object

Source reference needed to construct location instance

Returns:JsonLocation

Location pointing to the point where the context start marker was found (or written); never null.

Annotations
@Deprecated
Since
2.9
getTypeDescback to summary
public final String getTypeDesc()

Deprecated

Since 2.8 use typeDesc instead

Returns:String

Type description String

Annotations
@Deprecated
hasCurrentIndexback to summary
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:boolean

True if this context has value index to access, false otherwise

Since
2.9
hasCurrentNameback to summary
public boolean hasCurrentName()
Returns:boolean

True if a call to getCurrentName() would return non-null name; false otherwise

Since
2.9
hasPathSegmentback to summary
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)
and if so, return `true`; otherwise return `false`. Latter case includes Root context (always), and Object/Array contexts before any entries/elements have been read or written.

Method is mostly used to determine whether this context should be used for constructing JsonPointer

Returns:boolean

True if this context has value path segment to access, false otherwise

Since
2.9
inArrayback to summary
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:boolean

True if this context represents an Array; false otherwise

inObjectback to summary
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:boolean

True if this context represents an Object; false otherwise

inRootback to summary
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:boolean

True if this context represents a sequence of Root values; false otherwise

pathAsPointerback to summary
public JsonPointer pathAsPointer()

Factory method for constructing a JsonPointer that 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:JsonPointer

Pointer instance constructed

Since
2.9
pathAsPointerback to summary
public JsonPointer pathAsPointer(boolean includeRoot)

Factory method for constructing a JsonPointer that points to the current location within the stream that this context is for, optionally including "root value index"

Parameters
includeRoot:boolean

Whether root-value offset is included as the first segment or not;

Returns:JsonPointer

Pointer instance constructed

Since
2.9
setCurrentValueback to summary
public void setCurrentValue(Object v)

Method to call to pass value to be returned via getCurrentValue; typically called indirectly through JsonParser#setCurrentValue or JsonGenerator#setCurrentValue).

Parameters
v:Object

Current value to assign to this context

Since
2.5
startLocationback to summary
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 return JsonLocation#NA; this is what the default implementation does.

Parameters
srcRef:ContentReference

Source reference needed to construct location instance

Returns:JsonLocation

Location pointing to the point where the context start marker was found (or written); never null.

Since
2.13
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Overridden to provide developer readable "JsonPath" representation of the context.

Returns:String

Simple developer-readable description this context layer (note: NOT constructed with parents, unlike pathAsPointer)

Annotations
@Override
Since
2.9
typeDescback to summary
public 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:String

Type description String

Since
2.8