Class SimpleStreamReadContext

java.lang.Object
tools.jackson.core.TokenStreamContext
tools.jackson.core.util.SimpleStreamReadContext

public class SimpleStreamReadContext extends TokenStreamContext
Basic implementation of TokenStreamContext useful for most format backend JsonParser implementations (with notable exception of JSON that needs bit more advanced state).
Since:
3.0
  • Field Details

    • _parent

      protected final SimpleStreamReadContext _parent
      Parent context for this context; null for root context.
    • _dups

      protected DupDetector _dups
    • _childToRecycle

      protected SimpleStreamReadContext _childToRecycle
    • _currentName

      protected String _currentName
    • _currentValue

      protected Object _currentValue
    • _lineNr

      protected int _lineNr
    • _columnNr

      protected int _columnNr
  • Constructor Details

  • Method Details

    • reset

      protected void reset(int type, int lineNr, int colNr)
    • currentValue

      public Object currentValue()
      Description copied from class: TokenStreamContext
      Method for accessing currently active value being used by data-binding (as the source of streaming data to write, or destination of data being read), at this level in hierarchy.

      Note that "current value" is NOT populated (or used) by Streaming parser or generator; it is only used by higher-level data-binding functionality. The reason it is included here is that it can be stored and accessed hierarchically, and gets passed through data-binding.

      Overrides:
      currentValue in class TokenStreamContext
      Returns:
      Currently active value, if one has been assigned.
    • assignCurrentValue

      public void assignCurrentValue(Object v)
      Description copied from class: TokenStreamContext
      Method to call to pass value to be returned via TokenStreamContext.currentValue(); typically called indirectly through JsonParser.assignCurrentValue(java.lang.Object) or JsonGenerator.assignCurrentValue(java.lang.Object)).
      Overrides:
      assignCurrentValue in class TokenStreamContext
      Parameters:
      v - Current value to assign to this context
    • createRootContext

      public static SimpleStreamReadContext createRootContext(int lineNr, int colNr, DupDetector dups)
    • createRootContext

      public static SimpleStreamReadContext createRootContext(DupDetector dups)
    • createChildArrayContext

      public SimpleStreamReadContext createChildArrayContext(int lineNr, int colNr)
    • createChildObjectContext

      public SimpleStreamReadContext createChildObjectContext(int lineNr, int colNr)
    • currentName

      public String currentName()
      Description copied from class: TokenStreamContext
      Method for accessing name associated with the current location. Non-null for PROPERTY_NAME and value events that directly follow Property names; null for root level and array values.
      Specified by:
      currentName in class TokenStreamContext
      Returns:
      Current property name within context, if any; null if none
      Since:
      3.0
    • hasCurrentName

      public boolean hasCurrentName()
      Overrides:
      hasCurrentName in class TokenStreamContext
    • getParent

      public SimpleStreamReadContext getParent()
      Description copied from class: TokenStreamContext
      Accessor for finding parent context of this context; will return null for root context.
      Specified by:
      getParent in class TokenStreamContext
      Returns:
      Parent context of this context, if any; null for Root contexts
    • startLocation

      public TokenStreamLocation startLocation(ContentReference srcRef)
      Description copied from class: TokenStreamContext
      Optional method that may be used to access starting location of this context: for example, in case of JSON `Object` context, offset at which `[` token was read or written. Often used for error reporting purposes. Implementations that do not keep track of such location are expected to return TokenStreamLocation.NA; this is what the default implementation does.
      Overrides:
      startLocation in class TokenStreamContext
      Parameters:
      srcRef - Source reference needed to construct location instance
      Returns:
      Location pointing to the point where the context start marker was found (or written); never null.
    • clearAndGetParent

      public SimpleStreamReadContext clearAndGetParent()
      Method that can be used to both clear the accumulated references (specifically value set with assignCurrentValue(Object)) that should not be retained, and returns parent (as would getParent() do). Typically called when closing the active context when encountering JsonToken.END_ARRAY or JsonToken.END_OBJECT.
      Returns:
      Parent context of this context node, if any; null for root context
    • getDupDetector

      public DupDetector getDupDetector()
    • valueRead

      public int valueRead()
      Method to call to advance index within current context: to be called when a new token found within current context (property name for objects, value for root and array contexts)
      Returns:
      Index after increment
    • setCurrentName

      public void setCurrentName(String name) throws StreamReadException
      Method called to indicate what the "current" name (Object property name just decoded) is: may also trigger duplicate detection.
      Parameters:
      name - Name of Object property encountered
      Throws:
      StreamReadException - If there is a duplicate name violation
    • _checkDup

      protected void _checkDup(DupDetector dd, String name) throws StreamReadException
      Throws:
      StreamReadException