Top Description Fields Constructors Methods
com.fasterxml.jackson.databind

public Class MappingIterator<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.*

Iterator exposed by ObjectMapper when binding sequence of objects. Extension is done to allow more convenient exposing of IOException (which basic Iterator does not expose)

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 DeserializationContext
_context

Context for deserialization, needed to pass through to deserializer

protected final JsonDeserializer<T>
_deserializer

Deserializer for individual element values.

protected final JsonParser
_parser

Underlying parser used for reading content to bind.

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 JavaType
_type

Type to bind individual elements to.

protected final T
_updatedValue

If not null, "value to update" instead of creating a new instance for each call.

protected static final MappingIterator<?>
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 succesfully 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
MappingIterator(JavaType type, JsonParser p, DeserializationContext ctxt, JsonDeserializer<?> deser, boolean
Whether we "own" the JsonParser passed or not: if true, it was created by ObjectReader and code here needs to close it; if false, it was passed by calling code and should not be closed by iterator.
managedParser
,
Object valueToUpdate)

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 static <T> MappingIterator<T>
emptyIterator()

Method for getting an "empty" iterator instance: one that never has more values; may be freely shared.

public JsonLocation

Returns:

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

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

public JsonParser
getParser()

Accessor for getting underlying parser this iterator uses.

public FormatSchema
getParserSchema()

Accessor for accessing FormatSchema that the underlying parser (as per getParser) is using, if any; only parser of schema-aware formats use schemas.

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.

_contextback to summary
protected final DeserializationContext _context

Context for deserialization, needed to pass through to deserializer

_deserializerback to summary
protected final JsonDeserializer<T> _deserializer

Deserializer for individual element values.

_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.

_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

_typeback to summary
protected final JavaType _type

Type to bind individual elements to.

_updatedValueback to summary
protected final T _updatedValue

If not null, "value to update" instead of creating a new instance for each call.

EMPTY_ITERATORback to summary
protected static final MappingIterator<?> EMPTY_ITERATOR
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 succesfully 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

MappingIteratorback to summary
protected MappingIterator(JavaType type, JsonParser p, DeserializationContext ctxt, JsonDeserializer<?> deser, boolean managedParser, Object valueToUpdate)
Parameters
managedParser:boolean

Whether we "own" the JsonParser passed or not: if true, it was created by ObjectReader and code here needs to close it; if false, it was passed by calling code and should not be closed by iterator.

Annotations
@SuppressWarnings:unchecked

Method Detail

_handleIOExceptionback to summary
protected <R> R _handleIOException(IOException e)
_handleMappingExceptionback to summary
protected <R> R _handleMappingException(JsonMappingException 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
emptyIteratorback to summary
public static <T> MappingIterator<T> emptyIterator()

Method for getting an "empty" iterator instance: one that never has more values; may be freely shared.

Annotations
@SuppressWarnings:unchecked
Since
2.10 Existed earlier but public since 2.10
getCurrentLocationback to summary
public JsonLocation getCurrentLocation()

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

Returns:JsonLocation

Location of the input stream of the underlying parser

Since
2.2.1
getParserback to summary
public JsonParser getParser()

Accessor for getting underlying parser this iterator uses.

Since
2.2
getParserSchemaback to summary
public FormatSchema getParserSchema()

Accessor for accessing FormatSchema that the underlying parser (as per getParser) is using, if any; only parser of schema-aware formats use schemas.

Since
2.2
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

Since
2.2
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)

Since
2.2
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

Since
2.5
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