com.fasterxml.jackson.core

Class JsonStreamContext

  • Direct Known Subclasses:
    JsonReadContext, JsonWriteContext, TokenFilterContext


    public abstract class JsonStreamContext
    extends Object
    Shared base class for streaming processing contexts used during reading and writing of Json content using Streaming API. This context is also exposed to applications: context object can be used by applications to get an idea of relative position of the parser/generator within json content being processed. This allows for some contextual processing: for example, output within Array context can differ from that of Object context.
    • Field Detail

      • _type

        protected int _type
      • _index

        protected int _index
        Index of the currently processed entry. Starts with -1 to signal that no entries have been started, and gets advanced each time a new entry is started, either by encountering an expected separator, or with new values if no separators are expected (the case for root context).
    • Constructor Detail

      • JsonStreamContext

        protected JsonStreamContext()
      • JsonStreamContext

        protected JsonStreamContext(JsonStreamContext base)
        Copy constructor used by sub-classes for creating copies for buffering.
        Since:
        2.9
      • JsonStreamContext

        protected JsonStreamContext(int type,
                                    int index)
        Since:
        2.9
    • Method Detail

      • getParent

        public abstract JsonStreamContext getParent()
        Accessor for finding parent context of this context; will return null for root context.
      • inArray

        public final boolean inArray()
        Method that returns true if this context is an Array context; that is, content is being read from or written to a Json Array.
      • inRoot

        public final boolean inRoot()
        Method that returns true if this context is a Root context; that is, content is being read from or written to without enclosing array or object structure.
      • inObject

        public final boolean inObject()
        Method that returns true if this context is an Object context; that is, content is being read from or written to a Json Object.
      • getTypeDesc

        @Deprecated
        public final String getTypeDesc()
        Deprecated. Since 2.8 use typeDesc() instead
        Method for accessing simple type description of current context; either ROOT (for root-level values), OBJECT (for field names and values of JSON Objects) or ARRAY (for values of JSON Arrays)
      • typeDesc

        public String typeDesc()
        Since:
        2.8
      • getEntryCount

        public final int getEntryCount()
        Returns:
        Number of entries that are complete and started.
      • getCurrentIndex

        public final int getCurrentIndex()
        Returns:
        Index of the currently processed entry, if any
      • hasCurrentIndex

        public boolean hasCurrentIndex()
        Method that may be called to verify whether this context has valid index: will return `false` before the first entry of Object context or before first element of Array context; otherwise returns `true`.
        Since:
        2.9
      • hasPathSegment

        public boolean hasPathSegment()
        Method that may be called to check if this context is either:
        • Object, with at least one entry written (partially or completely)
        • Array, with at least one entry written (partially or completely)
        and if so, return `true`; otherwise return `false`. Latter case includes Root context (always), and Object/Array contexts before any entries/elements have been read or written.

        Method is mostly used to determine whether this context should be used for constructing JsonPointer

        Since:
        2.9
      • getCurrentName

        public abstract String getCurrentName()
        Method for accessing name associated with the current location. Non-null for FIELD_NAME and value events that directly follow field names; null for root level and array values.
      • hasCurrentName

        public boolean hasCurrentName()
        Since:
        2.9
      • getCurrentValue

        public Object getCurrentValue()
        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.

        Returns:
        Currently active value, if one has been assigned.
        Since:
        2.5
      • pathAsPointer

        public JsonPointer pathAsPointer()
        Factory method for constructing a JsonPointer that points to the current location within the stream that this context is for, excluding information about "root context" (only relevant for multi-root-value cases)
        Since:
        2.9
      • pathAsPointer

        public JsonPointer pathAsPointer(boolean includeRoot)
        Factory method for constructing a JsonPointer that points to the current location within the stream that this context is for, optionally including "root value index"
        Parameters:
        includeRoot - Whether root-value offset is included as the first segment or not;
        Since:
        2.9
      • getStartLocation

        public JsonLocation getStartLocation(Object srcRef)
        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 JsonLocation.NA; this is what the default implementation does.
        Returns:
        Location pointing to the point where the context start marker was found (or written); never `null`.

        NOTE: demoted from JsonReadContext in 2.9, to allow use for "non-standard" read contexts.

        Since:
        2.9
      • toString

        public String toString()
        Overridden to provide developer readable "JsonPath" representation of the context.
        Overrides:
        toString in class Object
        Since:
        2.9

Copyright © 2008–2017 FasterXML. All rights reserved.