Class MappingIterator<T>

java.lang.Object
tools.jackson.databind.MappingIterator<T>
All Implemented Interfaces:
Closeable, AutoCloseable, Iterator<T>

public class MappingIterator<T> extends Object implements Iterator<T>, Closeable
Iterator exposed by ObjectMapper when binding sequence of objects. Extension is done to allow more convenient access to some aspects of databinding, such as current location (see currentLocation().

NOTE: in Jackson 2.x exception handling required use of this class in many case (due to Jackson 2.x API exposing checked exceptions) but this is no longer necessary with Jackson 3.x.

  • Field Details

    • EMPTY_ITERATOR

      protected static final MappingIterator<?> EMPTY_ITERATOR
    • STATE_CLOSED

      protected static final int STATE_CLOSED
      State in which iterator is closed
      See Also:
    • STATE_NEED_RESYNC

      protected static final int STATE_NEED_RESYNC
      State in which value read failed
      See Also:
    • 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:
    • STATE_HAS_VALUE

      protected static final int STATE_HAS_VALUE
      State in which "hasNextValue()" has been succesfully called and deserializer can be called to fetch value
      See Also:
    • _type

      protected final JavaType _type
      Type to bind individual elements to.
    • _context

      protected final DeserializationContext _context
      Context for deserialization, needed to pass through to deserializer
    • _deserializer

      protected final ValueDeserializer<T> _deserializer
      Deserializer for individual element values.
    • _parser

      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.
    • _seqContext

      protected final TokenStreamContext _seqContext
      Context to resynchronize to, in case an exception is encountered but caller wants to try to read more elements.
    • _updatedValue

      protected final T _updatedValue
      If not null, "value to update" instead of creating a new instance for each call.
    • _closeParser

      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.
    • _state

      protected int _state
      State of the iterator
  • Constructor Details

    • MappingIterator

      protected MappingIterator(JavaType type, JsonParser p, DeserializationContext ctxt, ValueDeserializer<?> deser, boolean managedParser, Object valueToUpdate)
      Parameters:
      managedParser - 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.
    • MappingIterator

      protected MappingIterator(MappingIterator<T> src)
      Copy-constructor that sub-classes can use when creating new instances by fluent-style construction.
      Since:
      2.19
  • Method Details

    • emptyIterator

      public static <T> MappingIterator<T> emptyIterator()
      Method for getting an "empty" iterator instance: one that never has more values; may be freely shared.
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • next

      public T next()
      Specified by:
      next in interface Iterator<T>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • hasNextValue

      public boolean hasNextValue() throws JacksonException
      Equivalent of next() but one that may throw checked exceptions from Jackson due to invalid input.
      Throws:
      JacksonException
    • nextValue

      public T nextValue() throws JacksonException
      Throws:
      JacksonException
    • readAll

      public List<T> readAll() throws JacksonException
      Convenience method for reading all entries accessible via this iterator; resulting container will be a ArrayList.
      Returns:
      List of entries read
      Throws:
      JacksonException
    • readAll

      public <L extends List<? super T>> L readAll(L resultList) throws JacksonException
      Convenience method for reading all entries accessible via this iterator
      Returns:
      List of entries read (same as passed-in argument)
      Throws:
      JacksonException
    • readAll

      public <C extends Collection<? super T>> C readAll(C results) throws JacksonException
      Convenience method for reading all entries accessible via this iterator
      Throws:
      JacksonException
    • parser

      public JsonParser parser()
      Accessor for getting underlying parser this iterator uses.
    • parserSchema

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

      public TokenStreamLocation currentLocation()
      Convenience method, functionally equivalent to: iterator.getParser().getCurrentLocation()
      Returns:
      Location of the input stream of the underlying parser
    • _resync

      protected void _resync() throws JacksonException
      Throws:
      JacksonException
    • _throwNoSuchElement

      protected <R> R _throwNoSuchElement()