public class JsonPointer extends 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 |
---|---|
protected String |
_asString
We will retain representation of the pointer, as a String,
so that
toString() should be as efficient as possible. |
protected JsonPointer |
_head
Reference from currently matching segment (if any) to node
before leaf.
|
protected int |
_matchingElementIndex |
protected String |
_matchingPropertyName |
protected JsonPointer |
_nextSegment
Reference to rest of the pointer beyond currently matching
segment (if any); null if this pointer refers to the matching
segment.
|
protected static JsonPointer |
EMPTY
Marker instance used to represent segment that matches current
node or position (that is, returns true for
matches() ). |
static char |
SEPARATOR
Character used to separate segments.
|
Modifier | Constructor and Description |
---|---|
protected |
JsonPointer()
Constructor used for creating "empty" instance, used to represent
state that matches current node.
|
protected |
JsonPointer(String fullString,
String segment,
int matchIndex,
JsonPointer next) |
protected |
JsonPointer(String fullString,
String segment,
JsonPointer next)
Constructor used for creating non-empty Segments
|
Modifier and Type | Method and Description |
---|---|
protected JsonPointer |
_constructHead() |
protected JsonPointer |
_constructHead(int suffixLength,
JsonPointer last) |
protected static JsonPointer |
_parseQuotedTail(String input,
int i)
Method called to parse tail of pointer path, when a potentially
escaped character has been seen.
|
protected static JsonPointer |
_parseTail(String input) |
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(String input)
Factory method that parses given input and construct matching pointer
instance, if it represents a valid JSON Pointer: if not, a
IllegalArgumentException is thrown. |
boolean |
equals(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() |
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(String name)
Method that may be called to see if the pointer would match property
(of a JSON Object) with given name.
|
JsonPointer |
matchProperty(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.
|
String |
toString() |
static JsonPointer |
valueOf(String input)
Alias for
compile(java.lang.String) ; added to make instances automatically
deserializable by Jackson databind. |
public static final char SEPARATOR
protected static final JsonPointer EMPTY
matches()
).protected final JsonPointer _nextSegment
protected volatile JsonPointer _head
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).
protected final String _asString
toString()
should be as efficient as possible.protected final String _matchingPropertyName
protected final int _matchingElementIndex
protected JsonPointer()
protected JsonPointer(String fullString, String segment, JsonPointer next)
protected JsonPointer(String fullString, String segment, int matchIndex, JsonPointer next)
public static JsonPointer compile(String input) throws IllegalArgumentException
IllegalArgumentException
is thrown.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(String input)
compile(java.lang.String)
; added to make instances automatically
deserializable by Jackson databind.public static JsonPointer forPath(JsonStreamContext context, boolean includeRoot)
JsonStreamContext
points to.context
- Context to build pointer expression fotincludeRoot
- Whether to include number offset for virtual "root context"
or not.public boolean matches()
public 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(String name)
public JsonPointer matchProperty(String name)
public boolean matchesElement(int index)
public JsonPointer matchElement(int index)
public JsonPointer tail()
public JsonPointer head()
tail()
that
would return "/branch/leaf").
For leafprotected static JsonPointer _parseTail(String input)
protected static JsonPointer _parseQuotedTail(String input, int i)
input
- Full input for the tail being parsedi
- Offset to character after tildeprotected JsonPointer _constructHead()
protected JsonPointer _constructHead(int suffixLength, JsonPointer last)
Copyright © 2018 JBoss by Red Hat. All rights reserved.