Package com.fasterxml.jackson.jr.ob
Class ValueIterator<T>
java.lang.Object
com.fasterxml.jackson.jr.ob.ValueIterator<T>
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterator<T>
Iterator exposed by
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanFlag that indicates whether inputJsonParsershould be closed when we are done or not; generally only called when caller did not pass JsonParser.protected final intMode: kind of values we are iterating overprotected final com.fasterxml.jackson.core.JsonParserUnderlying parser used for reading content to bind.protected final JSONReaderContext for deserialization, needed to pass through to deserializerprotected final com.fasterxml.jackson.core.JsonStreamContextContext to resynchronize to, in case an exception is encountered but caller wants to try to read more elements.protected intState of the iteratorprotected final com.fasterxml.jackson.core.TreeCodecIf "Tree" values are read, codec we need to use for bindingprotected final Class<?>Type to bind individual elements to.protected static final ValueIterator<?>protected static final intprotected static final intMode in which values are read as POJOs/Beans.protected static final intMode in which values are read as "Tree" values, as bound by registeredTreeCodec.protected static final intState in which iterator is closedprotected static final intState in which "hasNextValue()" has been successfully called and deserializer can be called to fetch valueprotected static final intState in which no recovery is needed, but "hasNextValue()" needs to be called firstprotected static final intState in which value read failed -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedValueIterator(int mode, Class<?> type, com.fasterxml.jackson.core.JsonParser p, JSONReader reader, com.fasterxml.jackson.core.TreeCodec treeCodec, boolean managedParser) -
Method Summary
Modifier and TypeMethodDescriptionprotected <R> Rprotected <R> Rprotected void_resync()protected <R> Rvoidclose()com.fasterxml.jackson.core.JsonLocationConvenience method, functionally equivalent to:iterator.getParser().getCurrentLocation()protected static <T> ValueIterator<T>com.fasterxml.jackson.core.JsonLocationDeprecated.com.fasterxml.jackson.core.JsonParserAccessor for getting underlying parser this iterator uses.booleanhasNext()booleanEquivalent ofnext()but one that may throw checked exceptions from Jackson due to invalid input.next()readAll()Convenience method for reading all entries accessible via this iterator; resulting container will be aArrayList.<C extends Collection<? super T>>
CreadAll(C results) Convenience method for reading all entries accessible via this iteratorreadAll(L resultList) Convenience method for reading all entries accessible via this iteratorvoidremove()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
MODE_BEAN
protected static final int MODE_BEANMode in which values are read as POJOs/Beans.- See Also:
-
MODE_ANY
protected static final int MODE_ANY- See Also:
-
MODE_TREE
protected static final int MODE_TREEMode in which values are read as "Tree" values, as bound by registeredTreeCodec.- See Also:
-
EMPTY_ITERATOR
-
STATE_CLOSED
protected static final int STATE_CLOSEDState in which iterator is closed- See Also:
-
STATE_NEED_RESYNC
protected static final int STATE_NEED_RESYNCState in which value read failed- See Also:
-
STATE_MAY_HAVE_VALUE
protected static final int STATE_MAY_HAVE_VALUEState in which no recovery is needed, but "hasNextValue()" needs to be called first- See Also:
-
STATE_HAS_VALUE
protected static final int STATE_HAS_VALUEState in which "hasNextValue()" has been successfully called and deserializer can be called to fetch value- See Also:
-
_mode
protected final int _modeMode: kind of values we are iterating over -
_type
Type to bind individual elements to. -
_reader
Context for deserialization, needed to pass through to deserializer -
_treeCodec
protected final com.fasterxml.jackson.core.TreeCodec _treeCodecIf "Tree" values are read, codec we need to use for binding -
_parser
protected final com.fasterxml.jackson.core.JsonParser _parserUnderlying parser used for reading content to bind. Initialized as notnullbut set asnullwhen iterator is closed, to denote closing. -
_seqContext
protected final com.fasterxml.jackson.core.JsonStreamContext _seqContextContext to resynchronize to, in case an exception is encountered but caller wants to try to read more elements. -
_closeParser
protected final boolean _closeParserFlag that indicates whether inputJsonParsershould be closed when we are done or not; generally only called when caller did not pass JsonParser. -
_state
protected int _stateState of the iterator
-
-
Constructor Details
-
ValueIterator
protected ValueIterator(int mode, Class<?> type, com.fasterxml.jackson.core.JsonParser p, JSONReader reader, com.fasterxml.jackson.core.TreeCodec treeCodec, boolean managedParser) - Parameters:
managedParser- Whether we "own" theJsonParserpassed or not: if true, it was created byJsonand code here needs to close it; if false, it was passed by calling code and should not be closed by iterator.
-
-
Method Details
-
emptyIterator
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove() -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
hasNextValue
Equivalent ofnext()but one that may throw checked exceptions from Jackson due to invalid input.- Throws:
IOException
-
nextValue
- Throws:
IOException
-
readAll
Convenience method for reading all entries accessible via this iterator; resulting container will be aArrayList.- Returns:
- List of entries read
- Throws:
IOException
-
readAll
Convenience method for reading all entries accessible via this iterator- Returns:
- List of entries read (same as passed-in argument)
- Throws:
IOException
-
readAll
Convenience method for reading all entries accessible via this iterator- Throws:
IOException
-
getParser
public com.fasterxml.jackson.core.JsonParser getParser()Accessor for getting underlying parser this iterator uses. -
currentLocation
public com.fasterxml.jackson.core.JsonLocation currentLocation()Convenience method, functionally equivalent to:iterator.getParser().getCurrentLocation()- Returns:
- Location of the input stream of the underlying parser
- Since:
- 2.17
-
getCurrentLocation
Deprecated.Since 2.17 usecurrentLocation()instead -
_resync
- Throws:
IOException
-
_throwNoSuchElement
protected <R> R _throwNoSuchElement() -
_handleMappingException
-
_handleIOException
-
currentLocation()instead