Top Description Fields Constructors Methods
com.fasterxml.jackson.jr.ob

public Class ValueIterator<T>

extends Object
implements Iterator<T>, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, java.util.Iterator
Imports
java.io.Closeable, .IOException, java.util.*, com.fasterxml.jackson.core.*, com.fasterxml.jackson.jr.ob.impl.JSONReader

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

Modifier and TypeField and Description
protected final 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 final int
_mode

Mode: kind of values we are iterating over

protected final JsonParser
_parser

Underlying parser used for reading content to bind.

protected final JSONReader
_reader

Context for deserialization, needed to pass through to deserializer

protected final 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 final TreeCodec
_treeCodec

If "Tree" values are read, codec we need to use for binding

protected final Class<?>
_type

Type to bind individual elements to.

protected static final ValueIterator<?>
protected static final int
MODE_ANY

Mode in which values are read as "Simple" content, java.util.Maps, java.util.Lists, Strings, Numbers and Booleans.

protected static final int
MODE_BEAN

Mode in which values are read as POJOs/Beans.

protected static final int
MODE_TREE

Mode in which values are read as "Tree" values, as bound by registered TreeCodec.

protected static final int
STATE_CLOSED

State in which iterator is closed

protected static final int
STATE_HAS_VALUE

State in which "hasNextValue()" has been successfully called and deserializer can be called to fetch value

protected static final int
STATE_MAY_HAVE_VALUE

State in which no recovery is needed, but "hasNextValue()" needs to be called first

protected static final int
STATE_NEED_RESYNC

State in which value read failed

Constructor Summary

AccessConstructor and Description
protected
ValueIterator(int mode, Class<?> type, JsonParser p, JSONReader reader, TreeCodec treeCodec, boolean
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.
managedParser
)

Method Summary

Modifier and TypeMethod and Description
protected <R> R
protected <R> R
protected void
protected <R> R
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public JsonLocation

Returns:

Location of the input stream of the underlying parser
currentLocation
()

Convenience method, functionally equivalent to: iterator.getParser().getCurrentLocation()

protected static <T> ValueIterator<T>
public JsonLocation
getCurrentLocation()
Deprecated Since 2.17 use currentLocation() instead

public JsonParser
getParser()

Accessor for getting underlying parser this iterator uses.

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public boolean
hasNextValue()

Equivalent of next but one that may throw checked exceptions from Jackson due to invalid input.

public T
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public T
public List<T>

Returns:

List of entries read
readAll
()

Convenience method for reading all entries accessible via this iterator; resulting container will be a java.util.ArrayList.

public <L extends List<? super T>> L

Returns:

List of entries read (same as passed-in argument)
readAll
(L resultList)

Convenience method for reading all entries accessible via this iterator

public <C extends Collection<? super T>> C
readAll(C results)

Convenience method for reading all entries accessible via this iterator

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_closeParserback to summary
protected final 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.

_modeback to summary
protected final int _mode

Mode: kind of values we are iterating over

_parserback to summary
protected final JsonParser _parser

Underlying parser used for reading content to bind. Initialized as not null but set as null when iterator is closed, to denote closing.

_readerback to summary
protected final JSONReader _reader

Context for deserialization, needed to pass through to deserializer

_seqContextback to summary
protected final JsonStreamContext _seqContext

Context to resynchronize to, in case an exception is encountered but caller wants to try to read more elements.

_stateback to summary
protected int _state

State of the iterator

_treeCodecback to summary
protected final TreeCodec _treeCodec

If "Tree" values are read, codec we need to use for binding

_typeback to summary
protected final Class<?> _type

Type to bind individual elements to.

EMPTY_ITERATORback to summary
protected static final ValueIterator<?> EMPTY_ITERATOR
MODE_ANYback to summary
protected static final int MODE_ANY

Mode in which values are read as "Simple" content, java.util.Maps, java.util.Lists, Strings, Numbers and Booleans.

MODE_BEANback to summary
protected static final int MODE_BEAN

Mode in which values are read as POJOs/Beans.

MODE_TREEback to summary
protected static final int MODE_TREE

Mode in which values are read as "Tree" values, as bound by registered TreeCodec.

STATE_CLOSEDback to summary
protected static final int STATE_CLOSED

State in which iterator is closed

STATE_HAS_VALUEback to summary
protected static final int STATE_HAS_VALUE

State in which "hasNextValue()" has been successfully called and deserializer can be called to fetch value

STATE_MAY_HAVE_VALUEback to summary
protected static final int STATE_MAY_HAVE_VALUE

State in which no recovery is needed, but "hasNextValue()" needs to be called first

STATE_NEED_RESYNCback to summary
protected static final int STATE_NEED_RESYNC

State in which value read failed

Constructor Detail

ValueIteratorback to summary
protected ValueIterator(int mode, Class<?> type, JsonParser p, JSONReader reader, TreeCodec treeCodec, boolean managedParser)
Parameters
managedParser:boolean

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.

Method Detail

_handleIOExceptionback to summary
protected <R> R _handleIOException(IOException e)
_handleMappingExceptionback to summary
protected <R> R _handleMappingException(JSONObjectException e)
_resyncback to summary
protected void _resync() throws IOException
_throwNoSuchElementback to summary
protected <R> R _throwNoSuchElement()
closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
currentLocationback to summary
public JsonLocation currentLocation()

Convenience method, functionally equivalent to: iterator.getParser().getCurrentLocation()

Returns:JsonLocation

Location of the input stream of the underlying parser

Since
2.17
emptyIteratorback to summary
protected static <T> ValueIterator<T> emptyIterator()
Annotations
@SuppressWarnings:unchecked
getCurrentLocationback to summary
public JsonLocation getCurrentLocation()

Deprecated

Since 2.17 use currentLocation() instead

Annotations
@Deprecated
getParserback to summary
public JsonParser getParser()

Accessor for getting underlying parser this iterator uses.

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
hasNextValueback to summary
public boolean hasNextValue() throws IOException

Equivalent of next but one that may throw checked exceptions from Jackson due to invalid input.

nextback to summary
public T next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:T

the next element in the iteration

Annotations
@SuppressWarnings:unchecked
@Override
nextValueback to summary
public T nextValue() throws IOException
readAllback to summary
public List<T> readAll() throws IOException

Convenience method for reading all entries accessible via this iterator; resulting container will be a java.util.ArrayList.

Returns:List<T>

List of entries read

readAllback to summary
public <L extends List<? super T>> L readAll(L resultList) throws IOException

Convenience method for reading all entries accessible via this iterator

Returns:L

List of entries read (same as passed-in argument)

readAllback to summary
public <C extends Collection<? super T>> C readAll(C results) throws IOException

Convenience method for reading all entries accessible via this iterator

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override