Package com.fasterxml.jackson.core
Class JsonPointer
- java.lang.Object
-
- com.fasterxml.jackson.core.JsonPointer
-
public class JsonPointer extends java.lang.Object
Implementation of JSON Pointer specification. Pointer instances can be used to locate logical JSON nodes for things like tree traversal (seeTreeNode.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
-
-
Field Summary
Fields Modifier and Type Field Description static char
SEPARATOR
Character used to separate segments.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 constructedJsonPointer
instance that starts with all segments of `this`, followed by all segments of `tail`.static JsonPointer
compile(java.lang.String input)
Factory method that parses given input and construct matching pointer instance, if it represents a valid JSON Pointer: if not, aIllegalArgumentException
is thrown.static JsonPointer
empty()
Accessor for an "empty" expression, that is, one you can get by callingcompile(java.lang.String)
with "" (empty String).boolean
equals(java.lang.Object o)
static JsonPointer
forPath(JsonStreamContext context, boolean includeRoot)
Factory method that will construct a pointer instance that describes path to location givenJsonStreamContext
points to.int
getMatchingIndex()
java.lang.String
getMatchingProperty()
int
hashCode()
JsonPointer
head()
Accessor for getting a pointer instance that is identical to this instance except that the last segment has been dropped.JsonPointer
last()
Returns the leaf of current JSON Pointer expression.JsonPointer
matchElement(int index)
boolean
matches()
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.boolean
matchesProperty(java.lang.String name)
Method that may be called to see if the pointer would match property (of a JSON Object) with given name.JsonPointer
matchProperty(java.lang.String name)
boolean
mayMatchElement()
boolean
mayMatchProperty()
JsonPointer
tail()
Accessor for getting a "sub-pointer", instance where current segment has been removed and pointer includes rest of segments.java.lang.String
toString()
static JsonPointer
valueOf(java.lang.String input)
Alias forcompile(java.lang.String)
; added to make instances automatically deserializable by Jackson databind.
-
-
-
Field Detail
-
SEPARATOR
public static final char SEPARATOR
Character used to separate segments.- Since:
- 2.9
- See Also:
- Constant Field Values
-
-
Method Detail
-
compile
public static JsonPointer compile(java.lang.String input) throws java.lang.IllegalArgumentException
Factory method that parses given input and construct matching pointer instance, if it represents a valid JSON Pointer: if not, aIllegalArgumentException
is thrown.- Throws:
java.lang.IllegalArgumentException
- Thrown if the input does not present a valid JSON Pointer expression: currently the only such expression is one that does NOT start with a slash ('/').
-
valueOf
public static JsonPointer valueOf(java.lang.String input)
Alias forcompile(java.lang.String)
; added to make instances automatically deserializable by Jackson databind.
-
empty
public static JsonPointer empty()
Accessor for an "empty" expression, that is, one you can get by callingcompile(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 givenJsonStreamContext
points to.- Parameters:
context
- Context to build pointer expression fotincludeRoot
- Whether to include number offset for virtual "root context" or not.- Since:
- 2.9
-
matches
public boolean matches()
-
getMatchingProperty
public java.lang.String getMatchingProperty()
-
getMatchingIndex
public int getMatchingIndex()
-
mayMatchProperty
public boolean mayMatchProperty()
- Returns:
- True if the root selector matches property name (that is, could match field value of JSON Object node)
-
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(java.lang.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
-
matchProperty
public JsonPointer matchProperty(java.lang.String name)
-
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 totail()
that would return "/branch/leaf"). For leaf- Since:
- 2.5
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
-