I'm using the Streaming API JsonParser of the Jackson library to do some custom json parsing in java.
Is there a way of achieving functionality similar to a peek()
method, where the next token is returned but the cursor position is not moved forward?
The use case for this is similar to the following:
JsonParser parser = new JsonFactory().createParser(inputStream);
while(parser.peek() != JsonToken.START_ARRAY){
...do something with the current token...
}
The code examples I've seen for Jackson use the nextToken()
method for the above case, which unfortunately also moves the cursor forward in the stream.
Is peek()
possible with Jackson out-of-the-box, or perhaps achievable with an additional method?
NB. not interested in other libraries, so no "library x does all this and the kitchen sink" type answers please.