public class JsonPointer
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
static char |
SEPARATOR
Character used to separate segments.
|
Modifier and Type | Method and 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 constructed
JsonPointer instance that starts with all segments
of `this`, followed by all segments of `tail`. |
static JsonPointer |
compile(java.lang.String expr)
Factory method that parses given input and construct matching pointer
instance, if it represents a valid JSON Pointer: if not, a
IllegalArgumentException is thrown. |
static JsonPointer |
empty()
Accessor for an "empty" expression, that is, one you can get by
calling
compile(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 given
JsonStreamContext 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() |
JsonPointer |
matchElement(int index)
Method that may be called to check whether the pointer head (first segment)
matches specified Array index and if so, return
JsonPointer that represents rest of the path after match. |
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 head (first segment)
would match property (of a JSON Object) with given name.
|
JsonPointer |
matchProperty(java.lang.String name)
Method that may be called to check whether the pointer head (first segment)
matches specified Object property (by name) and if so, return
JsonPointer that represents rest of the path after match. |
boolean |
mayMatchElement() |
boolean |
mayMatchProperty() |
JsonPointer |
tail()
Accessor for getting a "sub-pointer" (or sub-path), instance where current segment
has been removed and pointer includes rest of the segments.
|
java.lang.String |
toString() |
static JsonPointer |
valueOf(java.lang.String expr)
Alias for
compile(java.lang.String) ; added to make instances automatically
deserializable by Jackson databind. |
public static final char SEPARATOR
public static JsonPointer compile(java.lang.String expr) throws java.lang.IllegalArgumentException
IllegalArgumentException
is thrown.expr
- Pointer expression to compileJsonPointer
path expressionjava.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 ('/').public static JsonPointer valueOf(java.lang.String expr)
compile(java.lang.String)
; added to make instances automatically
deserializable by Jackson databind.expr
- Pointer expression to compileJsonPointer
path expressionpublic static JsonPointer empty()
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.
public static JsonPointer forPath(JsonStreamContext context, boolean includeRoot)
JsonStreamContext
points to.context
- Context to build pointer expression forincludeRoot
- Whether to include number offset for virtual "root context"
or not.JsonPointer
path to location of given contextpublic boolean matches()
public java.lang.String getMatchingProperty()
public int getMatchingIndex()
public boolean mayMatchProperty()
public boolean mayMatchElement()
public JsonPointer last()
public JsonPointer append(JsonPointer tail)
JsonPointer
instance that starts with all segments
of `this`, followed by all segments of `tail`.
tail
- JsonPointer
instance to append to this one, to create a new pointer instancepublic boolean matchesProperty(java.lang.String name)
name
- Name of Object property to matchTrue
if the pointer head matches specified property namepublic JsonPointer matchProperty(java.lang.String name)
JsonPointer
that represents rest of the path after match.
If there is no match, null
is returned.name
- Name of Object property to matchnull
otherwisepublic boolean matchesElement(int index)
index
- Index of Array element to matchTrue
if the pointer head matches specified Array indexpublic JsonPointer matchElement(int index)
JsonPointer
that represents rest of the path after match.
If there is no match, null
is returned.index
- Index of Array element to matchnull
otherwisepublic JsonPointer tail()
null
.
Note that this is a very cheap method to call as it simply returns "next" segment (which has been constructed when pointer instance was constructed).
null
if this pointer only
has the current segmentpublic JsonPointer head()
tail()
that
would return "/branch/leaf").
Note that whereas tail()
is a very cheap operation to call (as "tail" already
exists for single-linked forward direction), this method has to fully
construct a new instance by traversing the chain of segments.
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
Copyright © 2010 - 2023 Adobe. All Rights Reserved