java.lang.Object
tools.jackson.core.JsonParser
tools.jackson.core.util.JsonParserDelegate
tools.jackson.core.util.JsonParserSequence
- All Implemented Interfaces:
Closeable,AutoCloseable,Versioned
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
-
Nested Class Summary
Nested classes/interfaces inherited from class tools.jackson.core.JsonParser
JsonParser.NumberType, JsonParser.NumberTypeFP -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanConfiguration that determines whether state of parsers is first verified to see if parser already points to a token (that is,JsonParser.hasCurrentToken()returnstrue), and if so that token is first return beforeJsonParser.nextToken()is called.protected booleanFlag used to indicate that `JsonParser.nextToken()` should not be called, due to parser already pointing to a token.protected intIndex of the next parser in_parsers.protected final JsonParser[]Parsers other than the first one (which is initially assigned as delegate)Fields inherited from class tools.jackson.core.util.JsonParserDelegate
delegateFields inherited from class tools.jackson.core.JsonParser
DEFAULT_READ_CAPABILITIES -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJsonParserSequence(boolean checkForExistingToken, JsonParser[] parsers) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFlattenedActiveParsers(List<JsonParser> listToAddIn) voidclose()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 featureStreamReadFeature.AUTO_CLOSE_SOURCEis enabled.intMethod that is most useful for debugging or testing; returns actual number of underlying parsers sequence was constructed with (nor just ones remaining active)static JsonParserSequencecreateFlattened(boolean checkForExistingToken, JsonParser first, JsonParser second) Method that will construct a sequence (possibly a sequence) that contains all given sub-parsers.nextName()Method that fetches next token (as if callingJsonParser.nextToken()) and verifies whether it isJsonToken.PROPERTY_NAME; if it is, returns same asJsonParser.currentName(), otherwise null.booleanMethod that fetches next token (as if callingJsonParser.nextToken()) and verifies whether it isJsonToken.PROPERTY_NAMEwith specified name and returns result of that comparison.intnextNameMatch(PropertyNameMatcher matcher) Method that tries to match next token from stream asJsonToken.PROPERTY_NAME, and if so, further match it to one of pre-specified (field) names.Main iteration method, which will advance stream enough to determine type of the next token, if any.Need to override, re-implement similar to how method defined inParserMinimalBase, to keep state correct here.protected JsonTokenprotected booleanMethod 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.Methods inherited from class tools.jackson.core.util.JsonParserDelegate
assignCurrentValue, canParseAsync, canReadObjectId, canReadTypeId, clearCurrentToken, currentLocation, currentName, currentNameMatch, currentToken, currentTokenCount, currentTokenId, currentTokenLocation, currentValue, delegate, finishToken, getBigIntegerValue, getBinaryValue, getBooleanValue, getByteValue, getDecimalValue, getDoubleValue, getEmbeddedObject, getFloatValue, getIntValue, getLastClearedToken, getLongValue, getNumberType, getNumberTypeFP, getNumberValue, getNumberValueDeferred, getNumberValueExact, getObjectId, getSchema, getShortValue, getString, getString, getStringCharacters, getStringLength, getStringOffset, getTypeId, getValueAsBoolean, getValueAsBoolean, getValueAsDouble, getValueAsDouble, getValueAsInt, getValueAsInt, getValueAsLong, getValueAsLong, getValueAsString, getValueAsString, hasCurrentToken, hasStringCharacters, hasToken, hasTokenId, isClosed, isEnabled, isExpectedNumberIntToken, isExpectedStartArrayToken, isExpectedStartObjectToken, isNaN, nextValue, nonBlockingInputFeeder, objectReadContext, readBinaryValue, readValueAs, readValueAs, readValueAs, readValueAsTree, streamReadCapabilities, streamReadConstraints, streamReadContext, streamReadFeatures, streamReadInputSource, versionMethods inherited from class tools.jackson.core.JsonParser
_constructReadException, _constructReadException, _constructReadException, _constructReadException, _constructReadException, _constructReadException, _reportUnsupportedOperation, getBinaryValue, getText, getTextCharacters, getTextLength, getTextOffset, nextBooleanValue, nextIntValue, nextLongValue, nextStringValue, readBinaryValue, releaseBuffered, releaseBuffered
-
Field Details
-
_parsers
Parsers other than the first one (which is initially assigned as delegate) -
_checkForExistingToken
protected final boolean _checkForExistingTokenConfiguration that determines whether state of parsers is first verified to see if parser already points to a token (that is,JsonParser.hasCurrentToken()returnstrue), and if so that token is first return beforeJsonParser.nextToken()is called. If enabled, this check is made; if disabled, no check is made andJsonParser.nextToken()is always called for all parsers.Default setting is
false(for backwards-compatibility) so that possible existing token is not considered for parsers. -
_nextParserIndex
protected int _nextParserIndexIndex of the next parser in_parsers. -
_hasToken
protected boolean _hasTokenFlag used to indicate that `JsonParser.nextToken()` should not be called, due to parser already pointing to a token.
-
-
Constructor Details
-
JsonParserSequence
-
-
Method Details
-
createFlattened
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- Flag passed to be assigned as_checkForExistingTokenfor resulting sequencefirst- First parser to traversesecond- Second parser to traverse- Returns:
- Sequence instance constructed
-
addFlattenedActiveParsers
-
close
Description copied from class:JsonParserCloses 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 featureStreamReadFeature.AUTO_CLOSE_SOURCEis enabled. Whether parser owns the input source depends on factory method that was used to construct instance (so checkJsonFactoryfor details, but the general idea is that if caller passes in closable resource (such asInputStreamorReader) parser does NOT own the source; but if it passes a reference (such asFileorURLand creates stream or reader it does own them.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classJsonParserDelegate- Throws:
JacksonException
-
nextToken
Description copied from class:JsonParserMain 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.- Overrides:
nextTokenin classJsonParserDelegate- Returns:
- Next token from the stream, if any found, or null to indicate end-of-input
- Throws:
JacksonException- for low-level read issuesStreamReadException- for decoding problems
-
skipChildren
Need to override, re-implement similar to how method defined inParserMinimalBase, to keep state correct here.- Overrides:
skipChildrenin classJsonParserDelegate- Returns:
- This parser, to allow call chaining
- Throws:
JacksonException- for low-level read issuesStreamReadException- for decoding problems
-
nextName
Description copied from class:JsonParserMethod that fetches next token (as if callingJsonParser.nextToken()) and verifies whether it isJsonToken.PROPERTY_NAME; if it is, returns same asJsonParser.currentName(), otherwise null.NOTE: in Jackson 2.x method was called
nextFieldName()- Overrides:
nextNamein classJsonParserDelegate- Returns:
- Name of the the
JsonToken.PROPERTY_NAMEparser advanced to, if any;nullif next token is of some other type - Throws:
JacksonException- for low-level read issuesStreamReadException- for decoding problems
-
nextName
Description copied from class:JsonParserMethod that fetches next token (as if callingJsonParser.nextToken()) and verifies whether it isJsonToken.PROPERTY_NAMEwith specified name and returns result of that comparison. It is functionally equivalent to:return (nextToken() == JsonToken.PROPERTY_NAME) && str.getValue().equals(currentName());
but may be faster for parser to verify, and can therefore be used if caller expects to get such a property name from input next.NOTE: in Jackson 2.x method was called
nextFieldName()- Overrides:
nextNamein classJsonParserDelegate- Parameters:
str- Property name to compare next token to (if next token isJsonToken.PROPERTY_NAME)- Returns:
Trueif parser advanced toJsonToken.PROPERTY_NAMEwith specified name;falseotherwise (different token or non-matching name)- Throws:
JacksonException- for low-level read issuesStreamReadException- for decoding problems
-
nextNameMatch
Description copied from class:JsonParserMethod that tries to match next token from stream asJsonToken.PROPERTY_NAME, and if so, further match it to one of pre-specified (field) names. If match succeeds, property index (non-negative `int`) is returned; otherwise one of marker constants fromPropertyNameMatcher.- Overrides:
nextNameMatchin classJsonParserDelegate- Parameters:
matcher- Matcher that will handle actual matching- Returns:
- Index of the matched property name, if non-negative, or a negative error
code otherwise (see
PropertyNameMatcherfor details) - Throws:
JacksonIOException- for low-level read issuesStreamReadException- for decoding problemsJacksonException
-
containedParsersCount
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:
- Number of actual underlying parsers this sequence has
-
switchToNext
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:
- True if switch succeeded; false otherwise
-
switchAndReturnNext
- Throws:
JacksonException
-