public class

JsonParserSequence

extends JsonParserDelegate
java.lang.Object
   ↳ com.fasterxml.jackson.core.JsonParser
     ↳ com.fasterxml.jackson.core.util.JsonParserDelegate
       ↳ com.fasterxml.jackson.core.util.JsonParserSequence

Class Overview

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

Summary

Fields
protected int _nextParser Index of the next parser in _parsers.
protected final JsonParser[] _parsers Parsers other than the first one (which is initially assigned as delegate)
[Expand]
Inherited Fields
From class com.fasterxml.jackson.core.util.JsonParserDelegate
From class com.fasterxml.jackson.core.JsonParser
Protected Constructors
JsonParserSequence(JsonParser[] parsers)
Public Methods
void 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 AUTO_CLOSE_SOURCE is enabled.
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)
static JsonParserSequence createFlattened(JsonParser first, JsonParser second)
Method that will construct a parser (possibly a sequence) that contains all given sub-parsers.
JsonToken nextToken()
Main iteration method, which will advance stream enough to determine type of the next token, if any.
Protected Methods
void addFlattenedActiveParsers(List<JsonParser> result)
boolean switchToNext()
Method that will switch active parser from the current one to next parser in sequence, if there is another parser left, making this the new delegate.
[Expand]
Inherited Methods
From class com.fasterxml.jackson.core.util.JsonParserDelegate
From class com.fasterxml.jackson.core.JsonParser
From class java.lang.Object
From interface com.fasterxml.jackson.core.Versioned
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Fields

protected int _nextParser

Index of the next parser in _parsers.

protected final JsonParser[] _parsers

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

Protected Constructors

protected JsonParserSequence (JsonParser[] parsers)

Public Methods

public void 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 AUTO_CLOSE_SOURCE is enabled. Whether parser owns the input source depends on factory method that was used to construct instance (so check 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.

Throws
IOException

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)

public static JsonParserSequence createFlattened (JsonParser first, JsonParser second)

Method that will construct a parser (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.

public JsonToken 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
  • Next token from the stream, if any found, or null to indicate end-of-input

Protected Methods

protected void addFlattenedActiveParsers (List<JsonParser> result)

protected boolean switchToNext ()

Method that will switch active parser from the current one to next parser in sequence, if there is another parser left, making this the new delegate. Old delegate is returned if switch succeeds.

Returns
  • True if switch succeeded; false otherwise