Class ValueIterator<T>

java.lang.Object
com.fasterxml.jackson.jr.ob.ValueIterator<T>
All Implemented Interfaces:
Closeable, AutoCloseable, Iterator<T>

public class ValueIterator<T> extends Object implements Iterator<T>, Closeable
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

    Fields
    Modifier and Type
    Field
    Description
    protected final boolean
    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: kind of values we are iterating over
    protected final com.fasterxml.jackson.core.JsonParser
    Underlying parser used for reading content to bind.
    protected final JSONReader
    Context for deserialization, needed to pass through to deserializer
    protected final com.fasterxml.jackson.core.JsonStreamContext
    Context to resynchronize to, in case an exception is encountered but caller wants to try to read more elements.
    protected int
    State of the iterator
    protected final com.fasterxml.jackson.core.TreeCodec
    If "Tree" values are read, codec we need to use for binding
    protected final Class<?>
    Type to bind individual elements to.
    protected static final ValueIterator<?>
     
    protected static final int
    Mode in which values are read as "Simple" content, Maps, Lists, Strings, Numbers and Booleans.
    protected static final int
    Mode in which values are read as POJOs/Beans.
    protected static final int
    Mode in which values are read as "Tree" values, as bound by registered TreeCodec.
    protected static final int
    State in which iterator is closed
    protected static final int
    State in which "hasNextValue()" has been successfully called and deserializer can be called to fetch value
    protected static final int
    State in which no recovery is needed, but "hasNextValue()" needs to be called first
    protected static final int
    State in which value read failed
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ValueIterator(int mode, Class<?> type, com.fasterxml.jackson.core.JsonParser p, JSONReader reader, com.fasterxml.jackson.core.TreeCodec treeCodec, boolean managedParser)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected <R> R
     
    protected <R> R
     
    protected void
     
    protected <R> R
     
    void
     
    com.fasterxml.jackson.core.JsonLocation
    Convenience method, functionally equivalent to: iterator.getParser().getCurrentLocation()
    protected static <T> ValueIterator<T>
     
    com.fasterxml.jackson.core.JsonLocation
    Deprecated.
    Since 2.17 use currentLocation() instead
    com.fasterxml.jackson.core.JsonParser
    Accessor for getting underlying parser this iterator uses.
    boolean
     
    boolean
    Equivalent of next() but one that may throw checked exceptions from Jackson due to invalid input.
     
     
    Convenience method for reading all entries accessible via this iterator; resulting container will be a ArrayList.
    <C extends Collection<? super T>>
    C
    readAll(C results)
    Convenience method for reading all entries accessible via this iterator
    <L extends List<? super T>>
    L
    readAll(L resultList)
    Convenience method for reading all entries accessible via this iterator
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.Iterator

    forEachRemaining
  • Field Details

    • MODE_BEAN

      protected static final int MODE_BEAN
      Mode in which values are read as POJOs/Beans.
      See Also:
    • MODE_ANY

      protected static final int MODE_ANY
      Mode in which values are read as "Simple" content, Maps, Lists, Strings, Numbers and Booleans.
      See Also:
    • MODE_TREE

      protected static final int MODE_TREE
      Mode in which values are read as "Tree" values, as bound by registered TreeCodec.
      See Also:
    • EMPTY_ITERATOR

      protected static final ValueIterator<?> 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 successfully called and deserializer can be called to fetch value
      See Also:
    • _mode

      protected final int _mode
      Mode: kind of values we are iterating over
    • _type

      protected final 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 not null but set as null 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 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

    • 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" 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 Details

    • emptyIterator

      protected static <T> ValueIterator<T> emptyIterator()
    • 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() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • hasNextValue

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

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

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

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

      public <C extends Collection<? super T>> C readAll(C results) throws IOException
      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 public com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
      Deprecated.
      Since 2.17 use currentLocation() instead
    • _resync

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

      protected <R> R _throwNoSuchElement()
    • _handleMappingException

      protected <R> R _handleMappingException(JSONObjectException e)
    • _handleIOException

      protected <R> R _handleIOException(IOException e)