public class ValueIterator<T> extends Object implements Iterator<T>, Closeable
JSON
when binding sequence of
objects. Extension is done to allow more convenient exposing of
IOException
(which basic Iterator
does not expose).
NOTE: adapted from `jackson-databind` MappingIterator
Modifier and Type | Field and Description |
---|---|
protected boolean |
_closeParser
Flag that indicates whether input
JsonParser should be closed
when we are done or not; generally only called when caller did not
pass JsonParser. |
protected int |
_mode
Mode: kind of values we are iterating over
|
protected JsonParser |
_parser
Underlying parser used for reading content to bind.
|
protected JSONReader |
_reader
Context for deserialization, needed to pass through to deserializer
|
protected JsonStreamContext |
_seqContext
Context to resynchronize to, in case an exception is encountered
but caller wants to try to read more elements.
|
protected int |
_state
State of the iterator
|
protected TreeCodec |
_treeCodec
If "Tree" values are read, codec we need to use for binding
|
protected Class<?> |
_type
Type to bind individual elements to.
|
protected static ValueIterator<?> |
EMPTY_ITERATOR |
protected static int |
MODE_ANY
|
protected static int |
MODE_BEAN
Mode in which values are read as POJOs/Beans.
|
protected static int |
MODE_TREE
Mode in which values are read as "Tree" values, as bound
by registered
TreeCodec . |
protected static int |
STATE_CLOSED
State in which iterator is closed
|
protected static int |
STATE_HAS_VALUE
State in which "hasNextValue()" has been successfully called
and deserializer can be called to fetch value
|
protected static int |
STATE_MAY_HAVE_VALUE
State in which no recovery is needed, but "hasNextValue()" needs
to be called first
|
protected static int |
STATE_NEED_RESYNC
State in which value read failed
|
Modifier | Constructor and Description |
---|---|
protected |
ValueIterator(int mode,
Class<?> type,
JsonParser p,
JSONReader reader,
TreeCodec treeCodec,
boolean managedParser) |
Modifier and Type | Method and Description |
---|---|
protected <R> R |
_handleIOException(IOException e) |
protected <R> R |
_handleMappingException(JSONObjectException e) |
protected void |
_resync() |
protected <R> R |
_throwNoSuchElement() |
void |
close() |
protected static <T> ValueIterator<T> |
emptyIterator() |
JsonLocation |
getCurrentLocation()
Convenience method, functionally equivalent to:
iterator.getParser().getCurrentLocation()
|
JsonParser |
getParser()
Accessor for getting underlying parser this iterator uses.
|
boolean |
hasNext() |
boolean |
hasNextValue()
Equivalent of
next() but one that may throw checked
exceptions from Jackson due to invalid input. |
T |
next() |
T |
nextValue() |
List<T> |
readAll()
Convenience method for reading all entries accessible via
this iterator; resulting container will be a
ArrayList . |
<C extends Collection<? super T>> |
readAll(C results)
Convenience method for reading all entries accessible via this iterator
|
<L extends List<? super T>> |
readAll(L resultList)
Convenience method for reading all entries accessible via
this iterator
|
void |
remove() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
protected static final int MODE_BEAN
protected static final int MODE_ANY
protected static final int MODE_TREE
TreeCodec
.protected static final ValueIterator<?> EMPTY_ITERATOR
protected static final int STATE_CLOSED
protected static final int STATE_NEED_RESYNC
protected static final int STATE_MAY_HAVE_VALUE
protected static final int STATE_HAS_VALUE
protected final int _mode
protected final Class<?> _type
protected final JSONReader _reader
protected final TreeCodec _treeCodec
protected final JsonParser _parser
null
but set as null
when
iterator is closed, to denote closing.protected final JsonStreamContext _seqContext
protected final boolean _closeParser
JsonParser
should be closed
when we are done or not; generally only called when caller did not
pass JsonParser.protected int _state
protected ValueIterator(int mode, Class<?> type, JsonParser p, JSONReader reader, TreeCodec treeCodec, boolean managedParser)
managedParser
- Whether we "own" the JsonParser
passed or not:
if true, it was created by Json
and code here needs to
close it; if false, it was passed by calling code and should not be
closed by iterator.protected static <T> ValueIterator<T> emptyIterator()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public boolean hasNextValue() throws IOException
next()
but one that may throw checked
exceptions from Jackson due to invalid input.IOException
public T nextValue() throws IOException
IOException
public List<T> readAll() throws IOException
ArrayList
.IOException
public <L extends List<? super T>> L readAll(L resultList) throws IOException
IOException
public <C extends Collection<? super T>> C readAll(C results) throws IOException
IOException
public JsonParser getParser()
public JsonLocation getCurrentLocation()
iterator.getParser().getCurrentLocation()
protected void _resync() throws IOException
IOException
protected <R> R _throwNoSuchElement()
protected <R> R _handleMappingException(JSONObjectException e)
protected <R> R _handleIOException(IOException e)
Copyright © 2020 FasterXML. All rights reserved.