com.fasterxml.jackson.core

Class JsonPointer



  • public class JsonPointer
    extends Object
    Implementation of JSON Pointer specification. Pointer instances can be used to locate logical JSON nodes for things like tree traversal (see TreeNode.at(com.fasterxml.jackson.core.JsonPointer)). It may be used in future for filtering of streaming JSON content as well (not implemented yet for 2.3).

    Instances are fully immutable and can be cached, shared between threads.

    Since:
    2.3
    Author:
    Tatu Saloranta
    • Property Detail

      • mayMatch

        public boolean mayMatchProperty
    • Field Detail

      • SEPARATOR

        public static final char SEPARATOR
        Character used to separate segments.
        Since:
        2.9
        See Also:
        Constant Field Values
      • EMPTY

        protected static final JsonPointer EMPTY
        Marker instance used to represent segment that matches current node or position (that is, returns true for matches()).
      • _nextSegment

        protected final JsonPointer _nextSegment
        Reference to rest of the pointer beyond currently matching segment (if any); null if this pointer refers to the matching segment.
      • _head

        protected volatile JsonPointer _head
        Reference from currently matching segment (if any) to node before leaf. Lazily constructed if/as needed.

        NOTE: we'll use `volatile` here assuming that this is unlikely to become a performance bottleneck. If it becomes one we can probably just drop it and things still should work (despite warnings as per JMM regarding visibility (and lack thereof) of unguarded changes).

        Since:
        2.5
      • _asString

        protected final String _asString
        We will retain representation of the pointer, as a String, so that toString() should be as efficient as possible.
      • _matchingPropertyName

        protected final String _matchingPropertyName
      • _matchingElementIndex

        protected final int _matchingElementIndex
    • Constructor Detail

      • JsonPointer

        protected JsonPointer()
        Constructor used for creating "empty" instance, used to represent state that matches current node.
      • JsonPointer

        protected JsonPointer(String fullString,
                              String segment,
                              JsonPointer next)
        Constructor used for creating non-empty Segments
      • JsonPointer

        protected JsonPointer(String fullString,
                              String segment,
                              int matchIndex,
                              JsonPointer next)
        Since:
        2.5
    • Method Detail

      • empty

        public static JsonPointer empty()
        Accessor for an "empty" expression, that is, one you can get by calling compile(java.lang.String) with "" (empty String).

        NOTE: this is different from expression for "/" which would instead match Object node property with empty String ("") as name.

        Since:
        2.10
      • forPath

        public static JsonPointer forPath(JsonStreamContext context,
                                          boolean includeRoot)
        Factory method that will construct a pointer instance that describes path to location given JsonStreamContext points to.
        Parameters:
        context - Context to build pointer expression fot
        includeRoot - Whether to include number offset for virtual "root context" or not.
        Since:
        2.9
      • matches

        public boolean matches()
      • getMatchingProperty

        public String getMatchingProperty()
      • getMatchingIndex

        public int getMatchingIndex()
      • mayMatchProperty

        public boolean mayMatchProperty()
      • mayMatchElement

        public boolean mayMatchElement()
        Returns:
        True if the root selector matches element index (that is, could match an element of JSON Array node)
      • last

        public JsonPointer last()
        Returns the leaf of current JSON Pointer expression. Leaf is the last non-null segment of current JSON Pointer.
        Since:
        2.5
      • append

        public JsonPointer append(JsonPointer tail)
        Mutant factory method that will return
        • `tail` if `this` instance is "empty" pointer, OR
        • `this` instance if `tail` is "empty" pointer, OR
        • Newly constructed JsonPointer instance that starts with all segments of `this`, followed by all segments of `tail`.
        Parameters:
        tail - JsonPointer instance to append to this one, to create a new pointer instance
        Returns:
        Either `this` instance, `tail`, or a newly created combination, as per description above.
      • matchesProperty

        public boolean matchesProperty(String name)
        Method that may be called to see if the pointer would match property (of a JSON Object) with given name.
        Since:
        2.5
      • matchesElement

        public boolean matchesElement(int index)
        Method that may be called to see if the pointer would match array element (of a JSON Array) with given index.
        Since:
        2.5
      • matchElement

        public JsonPointer matchElement(int index)
        Since:
        2.6
      • tail

        public JsonPointer tail()
        Accessor for getting a "sub-pointer", instance where current segment has been removed and pointer includes rest of segments. For matching state, will return null.
      • head

        public JsonPointer head()
        Accessor for getting a pointer instance that is identical to this instance except that the last segment has been dropped. For example, for JSON Point "/root/branch/leaf", this method would return pointer "/root/branch" (compared to tail() that would return "/branch/leaf"). For leaf
        Since:
        2.5
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • _parseQuotedTail

        protected static JsonPointer _parseQuotedTail(String input,
                                                      int i)
        Method called to parse tail of pointer path, when a potentially escaped character has been seen.
        Parameters:
        input - Full input for the tail being parsed
        i - Offset to character after tilde
      • _constructHead

        protected JsonPointer _constructHead()

Copyright © 2008–2019 FasterXML. All rights reserved.