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

public Class JsonParserSequence

extends JsonParserDelegate
Class Inheritance
Imports
java.io.IOException, java.util.*, com.fasterxml.jackson.core.*

Helper class that can be used to sequence multiple physical JsonParsers to create a single logical sequence of tokens, as a single JsonParser.

Fairly simple use of JsonParserDelegate: only need to override nextToken to handle transition

Field Summary

Modifier and TypeField and Description
protected final boolean
_checkForExistingToken

Configuration that determines whether state of parsers is first verified to see if parser already points to a token (that is, JsonParser#hasCurrentToken() returns true), and if so that token is first return before JsonParser#nextToken is called.

protected boolean
_hasToken

Flag used to indicate that `JsonParser.nextToken()` should not be called, due to parser already pointing to a token.

protected int
_nextParserIndex

Index of the next parser in _parsers.

protected final JsonParser[]
_parsers

Parsers other than the first one (which is initially assigned as delegate)

Inherited from com.fasterxml.jackson.core.util.JsonParserDelegate:
delegate

Constructor Summary

AccessConstructor and Description
protected
JsonParserSequence(JsonParser[] parsers)
Deprecated

protected
JsonParserSequence(boolean checkForExistingToken, JsonParser[] parsers)

Method Summary

Modifier and TypeMethod and Description
protected void
public void
close()

Overrides com.fasterxml.jackson.core.util.JsonParserDelegate.close.

Implements java.io.Closeable.close.

Closes the parser so that no further iteration or data access can be made; will also close the underlying input source if parser either owns the input source, or feature Feature#AUTO_CLOSE_SOURCE is enabled.

public int

Returns:

Number of actual underlying parsers this sequence has
containedParsersCount
()

Method that is most useful for debugging or testing; returns actual number of underlying parsers sequence was constructed with (nor just ones remaining active)

public static JsonParserSequence

Returns:

Sequence instance constructed
createFlattened
(boolean
Flag passed to be assigned as _checkForExistingToken for resulting sequence
checkForExistingToken
,
JsonParser
First parser to traverse
first
,
JsonParser
Second parser to traverse
second
)

Method that will construct a sequence (possibly a sequence) that contains all given sub-parsers.

public static JsonParserSequence
createFlattened(JsonParser first, JsonParser second)
Deprecated

public JsonToken
nextToken()

Overrides com.fasterxml.jackson.core.util.JsonParserDelegate.nextToken.

Main iteration method, which will advance stream enough to determine type of the next token, if any.

public JsonParser
skipChildren()

Overrides com.fasterxml.jackson.core.util.JsonParserDelegate.skipChildren.

Need to override, re-implement similar to how method defined in com.fasterxml.jackson.core.base.ParserMinimalBase, to keep state correct here.

protected JsonToken
protected boolean

Returns:

True if switch succeeded; false otherwise
switchToNext
()

Method that will switch active delegate parser from the current one to the next parser in sequence, if there is another parser left: if so, the next parser will become the active delegate parser.

Inherited from com.fasterxml.jackson.core.util.JsonParserDelegate:
assignCurrentValuecanReadObjectIdcanReadTypeIdcanUseSchemaclearCurrentTokencurrentLocationcurrentNamecurrentTokencurrentTokenIdcurrentTokenLocationcurrentValuedelegatedisableenablefinishTokengetBigIntegerValuegetBinaryValuegetBooleanValuegetByteValuegetCodecgetCurrentLocationgetCurrentNamegetCurrentTokengetCurrentTokenIdgetCurrentValuegetDecimalValuegetDoubleValuegetEmbeddedObjectgetFeatureMaskgetFloatValuegetInputSourcegetIntValuegetLastClearedTokengetLongValuegetNumberTypegetNumberValuegetNumberValueDeferredgetNumberValueExactgetObjectIdgetParsingContextgetReadCapabilitiesgetSchemagetShortValuegetTextgetTextgetTextCharactersgetTextLengthgetTextOffsetgetTokenLocationgetTypeIdgetValueAsBooleangetValueAsBooleangetValueAsDoublegetValueAsDoublegetValueAsIntgetValueAsIntgetValueAsLonggetValueAsLonggetValueAsStringgetValueAsStringhasCurrentTokenhasTextCharactershasTokenhasTokenIdisClosedisEnabledisExpectedNumberIntTokenisExpectedStartArrayTokenisExpectedStartObjectTokenisNaNnextValueoverrideCurrentNameoverrideFormatFeaturesoverrideStdFeaturesreadBinaryValuerequiresCustomCodecsetCodecsetCurrentValuesetFeatureMasksetSchemastreamReadConstraintsversion

Field Detail

_checkForExistingTokenback to summary
protected final boolean _checkForExistingToken

Configuration that determines whether state of parsers is first verified to see if parser already points to a token (that is, JsonParser#hasCurrentToken() returns true), and if so that token is first return before JsonParser#nextToken is called. If enabled, this check is made; if disabled, no check is made and JsonParser#nextToken is always called for all parsers.

Default setting is false (for backwards-compatibility) so that possible existing token is not considered for parsers.

Since
2.8
_hasTokenback to summary
protected boolean _hasToken

Flag used to indicate that `JsonParser.nextToken()` should not be called, due to parser already pointing to a token.

Since
2.8
_nextParserIndexback to summary
protected int _nextParserIndex

Index of the next parser in _parsers.

_parsersback to summary
protected final JsonParser[] _parsers

Parsers other than the first one (which is initially assigned as delegate)

Constructor Detail

JsonParserSequenceback to summary
protected JsonParserSequence(JsonParser[] parsers)

Deprecated

Annotations
@Deprecated
JsonParserSequenceback to summary
protected JsonParserSequence(boolean checkForExistingToken, JsonParser[] parsers)

Method Detail

addFlattenedActiveParsersback to summary
protected void addFlattenedActiveParsers(List<JsonParser> listToAddIn)
Annotations
@SuppressWarnings:resource
closeback to summary
public void close() throws IOException

Overrides com.fasterxml.jackson.core.util.JsonParserDelegate.close.

Implements java.io.Closeable.close.

Doc from com.fasterxml.jackson.core.JsonParser.close.

Closes the parser so that no further iteration or data access can be made; will also close the underlying input source if parser either owns the input source, or feature Feature#AUTO_CLOSE_SOURCE is enabled. Whether parser owns the input source depends on factory method that was used to construct instance (so check com.fasterxml.jackson.core.JsonFactory for details, but the general idea is that if caller passes in closable resource (such as InputStream or Reader) parser does NOT own the source; but if it passes a reference (such as java.io.File or java.net.URL and creates stream or reader it does own them.

Annotations
@Override
Exceptions
IOException:
if there is either an underlying I/O problem
containedParsersCountback to summary
public int containedParsersCount()

Method that is most useful for debugging or testing; returns actual number of underlying parsers sequence was constructed with (nor just ones remaining active)

Returns:int

Number of actual underlying parsers this sequence has

createFlattenedback to summary
public static JsonParserSequence createFlattened(boolean checkForExistingToken, JsonParser first, JsonParser second)

Method that will construct a sequence (possibly a sequence) that contains all given sub-parsers. All parsers given are checked to see if they are sequences: and if so, they will be "flattened", that is, contained parsers are directly added in a new sequence instead of adding sequences within sequences. This is done to minimize delegation depth, ideally only having just a single level of delegation.

Parameters
checkForExistingToken:boolean

Flag passed to be assigned as _checkForExistingToken for resulting sequence

first:JsonParser

First parser to traverse

second:JsonParser

Second parser to traverse

Returns:JsonParserSequence

Sequence instance constructed

createFlattenedback to summary
public static JsonParserSequence createFlattened(JsonParser first, JsonParser second)

Deprecated

Annotations
@Deprecated
nextTokenback to summary
public JsonToken nextToken() throws IOException

Overrides com.fasterxml.jackson.core.util.JsonParserDelegate.nextToken.

Doc from com.fasterxml.jackson.core.JsonParser.nextToken.

Main iteration method, which will advance stream enough to determine type of the next token, if any. If none remaining (stream has no content other than possible white space before ending), null will be returned.

Returns:JsonToken

Next token from the stream, if any found, or null to indicate end-of-input

Annotations
@Override
Exceptions
IOException:
for low-level read issues, or JsonParseException for decoding problems
skipChildrenback to summary
public JsonParser skipChildren() throws IOException

Overrides com.fasterxml.jackson.core.util.JsonParserDelegate.skipChildren.

Need to override, re-implement similar to how method defined in com.fasterxml.jackson.core.base.ParserMinimalBase, to keep state correct here.

Returns:JsonParser

Doc from com.fasterxml.jackson.core.JsonParser.skipChildren.

This parser, to allow call chaining

Annotations
@Override
Exceptions
IOException:

Doc from com.fasterxml.jackson.core.JsonParser.skipChildren.

for low-level read issues, or JsonParseException for decoding problems

switchAndReturnNextback to summary
protected JsonToken switchAndReturnNext() throws IOException
switchToNextback to summary
protected boolean switchToNext()

Method that will switch active delegate parser from the current one to the next parser in sequence, if there is another parser left: if so, the next parser will become the active delegate parser.

Returns:boolean

True if switch succeeded; false otherwise

Since
2.8