Package com.fasterxml.jackson.jr.ob
Class ValueIterator<T>
- java.lang.Object
-
- com.fasterxml.jackson.jr.ob.ValueIterator<T>
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.util.Iterator<T>
public class ValueIterator<T> extends java.lang.Object implements java.util.Iterator<T>, java.io.Closeable
Iterator exposed byJSON
when binding sequence of objects. Extension is done to allow more convenient exposing ofIOException
(which basicIterator
does not expose).NOTE: adapted from `jackson-databind`
MappingIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_closeParser
Flag that indicates whether inputJsonParser
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 overprotected com.fasterxml.jackson.core.JsonParser
_parser
Underlying parser used for reading content to bind.protected JSONReader
_reader
Context for deserialization, needed to pass through to deserializerprotected com.fasterxml.jackson.core.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 iteratorprotected com.fasterxml.jackson.core.TreeCodec
_treeCodec
If "Tree" values are read, codec we need to use for bindingprotected java.lang.Class<?>
_type
Type to bind individual elements to.protected static ValueIterator<?>
EMPTY_ITERATOR
protected static int
MODE_ANY
Mode in which values are read as "Simple" content,Map
s,List
s,String
s,Number
s andBoolean
s.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 registeredTreeCodec
.protected static int
STATE_CLOSED
State in which iterator is closedprotected static int
STATE_HAS_VALUE
State in which "hasNextValue()" has been successfully called and deserializer can be called to fetch valueprotected static int
STATE_MAY_HAVE_VALUE
State in which no recovery is needed, but "hasNextValue()" needs to be called firstprotected static int
STATE_NEED_RESYNC
State in which value read failed
-
Constructor Summary
Constructors Modifier Constructor Description protected
ValueIterator(int mode, java.lang.Class<?> type, com.fasterxml.jackson.core.JsonParser p, JSONReader reader, com.fasterxml.jackson.core.TreeCodec treeCodec, boolean managedParser)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <R> R
_handleIOException(java.io.IOException e)
protected <R> R
_handleMappingException(JSONObjectException e)
protected void
_resync()
protected <R> R
_throwNoSuchElement()
void
close()
protected static <T> ValueIterator<T>
emptyIterator()
com.fasterxml.jackson.core.JsonLocation
getCurrentLocation()
Convenience method, functionally equivalent to:iterator.getParser().getCurrentLocation()
com.fasterxml.jackson.core.JsonParser
getParser()
Accessor for getting underlying parser this iterator uses.boolean
hasNext()
boolean
hasNextValue()
Equivalent ofnext()
but one that may throw checked exceptions from Jackson due to invalid input.T
next()
T
nextValue()
java.util.List<T>
readAll()
Convenience method for reading all entries accessible via this iterator; resulting container will be aArrayList
.<C extends java.util.Collection<? super T>>
CreadAll(C results)
Convenience method for reading all entries accessible via this iterator<L extends java.util.List<? super T>>
LreadAll(L resultList)
Convenience method for reading all entries accessible via this iteratorvoid
remove()
-
-
-
Field Detail
-
MODE_BEAN
protected static final int MODE_BEAN
Mode in which values are read as POJOs/Beans.- See Also:
- Constant Field Values
-
MODE_ANY
protected static final int MODE_ANY
Mode in which values are read as "Simple" content,Map
s,List
s,String
s,Number
s andBoolean
s.- See Also:
- Constant Field Values
-
MODE_TREE
protected static final int MODE_TREE
Mode in which values are read as "Tree" values, as bound by registeredTreeCodec
.- See Also:
- Constant Field Values
-
EMPTY_ITERATOR
protected static final ValueIterator<?> EMPTY_ITERATOR
-
STATE_CLOSED
protected static final int STATE_CLOSED
State in which iterator is closed- See Also:
- Constant Field Values
-
STATE_NEED_RESYNC
protected static final int STATE_NEED_RESYNC
State in which value read failed- See Also:
- Constant Field Values
-
STATE_MAY_HAVE_VALUE
protected static final int STATE_MAY_HAVE_VALUE
State in which no recovery is needed, but "hasNextValue()" needs to be called first- See Also:
- Constant Field Values
-
STATE_HAS_VALUE
protected static final int STATE_HAS_VALUE
State in which "hasNextValue()" has been successfully called and deserializer can be called to fetch value- See Also:
- Constant Field Values
-
_mode
protected final int _mode
Mode: kind of values we are iterating over
-
_type
protected final java.lang.Class<?> _type
Type to bind individual elements to.
-
_reader
protected final JSONReader _reader
Context for deserialization, needed to pass through to deserializer
-
_treeCodec
protected final com.fasterxml.jackson.core.TreeCodec _treeCodec
If "Tree" values are read, codec we need to use for binding
-
_parser
protected final com.fasterxml.jackson.core.JsonParser _parser
Underlying parser used for reading content to bind. Initialized as notnull
but set asnull
when iterator is closed, to denote closing.
-
_seqContext
protected final com.fasterxml.jackson.core.JsonStreamContext _seqContext
Context to resynchronize to, in case an exception is encountered but caller wants to try to read more elements.
-
_closeParser
protected final boolean _closeParser
Flag that indicates whether inputJsonParser
should be closed when we are done or not; generally only called when caller did not pass JsonParser.
-
_state
protected int _state
State of the iterator
-
-
Constructor Detail
-
ValueIterator
protected ValueIterator(int mode, java.lang.Class<?> type, com.fasterxml.jackson.core.JsonParser p, JSONReader reader, com.fasterxml.jackson.core.TreeCodec treeCodec, boolean managedParser)
- Parameters:
managedParser
- Whether we "own" theJsonParser
passed or not: if true, it was created byJson
and code here needs to close it; if false, it was passed by calling code and should not be closed by iterator.
-
-
Method Detail
-
emptyIterator
protected static <T> ValueIterator<T> emptyIterator()
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfacejava.util.Iterator<T>
-
remove
public void remove()
- Specified by:
remove
in interfacejava.util.Iterator<T>
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
hasNextValue
public boolean hasNextValue() throws java.io.IOException
Equivalent ofnext()
but one that may throw checked exceptions from Jackson due to invalid input.- Throws:
java.io.IOException
-
nextValue
public T nextValue() throws java.io.IOException
- Throws:
java.io.IOException
-
readAll
public java.util.List<T> readAll() throws java.io.IOException
Convenience method for reading all entries accessible via this iterator; resulting container will be aArrayList
.- Returns:
- List of entries read
- Throws:
java.io.IOException
-
readAll
public <L extends java.util.List<? super T>> L readAll(L resultList) throws java.io.IOException
Convenience method for reading all entries accessible via this iterator- Returns:
- List of entries read (same as passed-in argument)
- Throws:
java.io.IOException
-
readAll
public <C extends java.util.Collection<? super T>> C readAll(C results) throws java.io.IOException
Convenience method for reading all entries accessible via this iterator- Throws:
java.io.IOException
-
getParser
public com.fasterxml.jackson.core.JsonParser getParser()
Accessor for getting underlying parser this iterator uses.
-
getCurrentLocation
public com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
Convenience method, functionally equivalent to:iterator.getParser().getCurrentLocation()
- Returns:
- Location of the input stream of the underlying parser
-
_resync
protected void _resync() throws java.io.IOException
- Throws:
java.io.IOException
-
_throwNoSuchElement
protected <R> R _throwNoSuchElement()
-
_handleMappingException
protected <R> R _handleMappingException(JSONObjectException e)
-
_handleIOException
protected <R> R _handleIOException(java.io.IOException e)
-
-