Package com.fasterxml.jackson.core.json
Class JsonReadContext
java.lang.Object
com.fasterxml.jackson.core.JsonStreamContext
com.fasterxml.jackson.core.json.JsonReadContext
Extension of
JsonStreamContext
, which implements
core methods needed, and also exposes
more complete API to parser implementation classes.-
Field Summary
Modifier and TypeFieldDescriptionprotected JsonReadContext
protected int
protected String
protected Object
protected DupDetector
protected int
protected final JsonReadContext
Parent context for this context; null for root context.Fields inherited from class com.fasterxml.jackson.core.JsonStreamContext
_index, _nestingDepth, _type, TYPE_ARRAY, TYPE_OBJECT, TYPE_ROOT
-
Constructor Summary
ConstructorDescriptionJsonReadContext
(JsonReadContext parent, int nestingDepth, DupDetector dups, int type, int lineNr, int colNr) JsonReadContext
(JsonReadContext parent, DupDetector dups, int type, int lineNr, int colNr) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionMethod that can be used to both clear the accumulated references (specifically value set withsetCurrentValue(Object)
) that should not be retained, and returns parent (as wouldgetParent()
do).createChildArrayContext
(int lineNr, int colNr) createChildObjectContext
(int lineNr, int colNr) static JsonReadContext
createRootContext
(int lineNr, int colNr, DupDetector dups) static JsonReadContext
createRootContext
(DupDetector dups) boolean
Method for accessing name associated with the current location.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.Accessor for finding parent context of this context; will return null for root context.getStartLocation
(Object rawSrc) Deprecated.boolean
void
reset
(int type, int lineNr, int colNr) Internal method to allow instance reuse: DO NOT USE unless you absolutely know what you are doing.void
setCurrentName
(String name) void
Method to call to pass value to be returned viaJsonStreamContext.getCurrentValue()
; typically called indirectly throughJsonParser.setCurrentValue(java.lang.Object)
orJsonGenerator.setCurrentValue(java.lang.Object)
).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.withDupDetector
(DupDetector dups) Methods inherited from class com.fasterxml.jackson.core.JsonStreamContext
getCurrentIndex, getEntryCount, getNestingDepth, getTypeDesc, hasCurrentIndex, hasPathSegment, inArray, inObject, inRoot, pathAsPointer, pathAsPointer, toString, typeDesc
-
Field Details
-
_parent
Parent context for this context; null for root context. -
_dups
-
_child
-
_currentName
-
_currentValue
- Since:
- 2.5
-
_lineNr
protected int _lineNr -
_columnNr
protected int _columnNr
-
-
Constructor Details
-
JsonReadContext
public JsonReadContext(JsonReadContext parent, int nestingDepth, DupDetector dups, int type, int lineNr, int colNr) - Parameters:
parent
- Parent context, if any (null
for Root context)nestingDepth
- Number of parents this context has (0 for Root context)dups
- Detector used for checking duplicate names, if any (null
if none)type
- Type to assign to this context nodelineNr
- Line of the starting position of this contextcolNr
- Column of the starting position of this context- Since:
- 2.15
-
JsonReadContext
@Deprecated public JsonReadContext(JsonReadContext parent, DupDetector dups, int type, int lineNr, int colNr) Deprecated.
-
-
Method Details
-
reset
public void reset(int type, int lineNr, int colNr) Internal method to allow instance reuse: DO NOT USE unless you absolutely know what you are doing. Clears up state (including "current value"), changes type to one specified; resets current duplicate-detection state (if any). Parent link left as-is since it isfinal
.NOTE: Public since 2.12.
- Parameters:
type
- Type to assign to this context nodelineNr
- Line of the starting position of this contextcolNr
- Column of the starting position of this context
-
withDupDetector
-
getCurrentValue
Description copied from class:JsonStreamContext
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.
- Overrides:
getCurrentValue
in classJsonStreamContext
- Returns:
- Currently active value, if one has been assigned.
-
setCurrentValue
Description copied from class:JsonStreamContext
Method to call to pass value to be returned viaJsonStreamContext.getCurrentValue()
; typically called indirectly throughJsonParser.setCurrentValue(java.lang.Object)
orJsonGenerator.setCurrentValue(java.lang.Object)
).- Overrides:
setCurrentValue
in classJsonStreamContext
- Parameters:
v
- Current value to assign to this context
-
createRootContext
-
createRootContext
-
createChildArrayContext
-
createChildObjectContext
-
getCurrentName
Description copied from class:JsonStreamContext
Method for accessing name associated with the current location. Non-null forFIELD_NAME
and value events that directly follow field names; null for root level and array values.- Specified by:
getCurrentName
in classJsonStreamContext
- Returns:
- Current field name within context, if any;
null
if none
-
hasCurrentName
public boolean hasCurrentName()- Overrides:
hasCurrentName
in classJsonStreamContext
- Returns:
True
if a call toJsonStreamContext.getCurrentName()
would return non-null
name;false
otherwise
-
getParent
Description copied from class:JsonStreamContext
Accessor for finding parent context of this context; will return null for root context.- Specified by:
getParent
in classJsonStreamContext
- Returns:
- Parent context of this context, if any;
null
for Root contexts
-
startLocation
Description copied from class:JsonStreamContext
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.- Overrides:
startLocation
in classJsonStreamContext
- 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
.
-
getStartLocation
Deprecated.- Overrides:
getStartLocation
in classJsonStreamContext
- Parameters:
rawSrc
- Source reference needed to construct location instance- Returns:
- Location pointing to the point where the context
start marker was found (or written); never
null
.
-
clearAndGetParent
Method that can be used to both clear the accumulated references (specifically value set withsetCurrentValue(Object)
) that should not be retained, and returns parent (as wouldgetParent()
do). Typically called when closing the active context when encounteringJsonToken.END_ARRAY
orJsonToken.END_OBJECT
.- Returns:
- Parent context of this context node, if any;
null
for root context - Since:
- 2.7
-
getDupDetector
-
expectComma
public boolean expectComma() -
setCurrentName
- Throws:
JsonProcessingException
-