Package io.fabric8.zjsonpatch
Class JsonPointer
- java.lang.Object
-
- io.fabric8.zjsonpatch.JsonPointer
-
public class JsonPointer extends Object
This class is ported from FlipKart zjsonpatch repository
-
-
Field Summary
Fields Modifier and Type Field Description static JsonPointerROOTA JSON pointer representing the root node of a JSON document
-
Constructor Summary
Constructors Constructor Description JsonPointer(List<io.fabric8.zjsonpatch.JsonPointer.RefToken> tokens)Constructs a new pointer from a list of reference tokens.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<io.fabric8.zjsonpatch.JsonPointer.RefToken>decompose()Decomposes this JSON pointer into its reference tokens.booleanequals(Object o)com.fasterxml.jackson.databind.JsonNodeevaluate(com.fasterxml.jackson.databind.JsonNode document)Takes a target document and resolves the node represented by this instance.io.fabric8.zjsonpatch.JsonPointer.RefTokenget(int index)Retrieves the reference token at the specified index.JsonPointergetParent()Creates a JSON pointer to the parent of the node represented by this instance.inthashCode()booleanisRoot()Indicates whether or not this instance points to the root of a JSON document.io.fabric8.zjsonpatch.JsonPointer.RefTokenlast()Retrieves the last reference token for this JSON pointer.static JsonPointerparse(String path)Parses a valid string representation of a JSON Pointer.StringtoString()Returns a string representation of this instance
-
-
-
Field Detail
-
ROOT
public static final JsonPointer ROOT
A JSON pointer representing the root node of a JSON document
-
-
Constructor Detail
-
JsonPointer
public JsonPointer(List<io.fabric8.zjsonpatch.JsonPointer.RefToken> tokens)
Constructs a new pointer from a list of reference tokens.- Parameters:
tokens- The list of reference tokens from which to construct the new pointer. This list is not modified.
-
-
Method Detail
-
parse
public static JsonPointer parse(String path) throws IllegalArgumentException
Parses a valid string representation of a JSON Pointer.- Parameters:
path- The string representation to be parsed.- Returns:
- An instance of
JsonPointerconforming to the specified string representation. - Throws:
IllegalArgumentException- The specified JSON Pointer is invalid.
-
isRoot
public boolean isRoot()
Indicates whether or not this instance points to the root of a JSON document.- Returns:
trueif this pointer represents the root node,falseotherwise.
-
toString
public String toString()
Returns a string representation of this instance- Overrides:
toStringin classObject- Returns:
- An RFC 6901 compliant string representation of this JSON pointer.
-
decompose
public List<io.fabric8.zjsonpatch.JsonPointer.RefToken> decompose()
Decomposes this JSON pointer into its reference tokens.- Returns:
- A list of
JsonPointer.RefTokens. Modifications to this list do not affect this instance.
-
get
public io.fabric8.zjsonpatch.JsonPointer.RefToken get(int index) throws IndexOutOfBoundsExceptionRetrieves the reference token at the specified index.- Parameters:
index- The desired reference token index.- Returns:
- The specified instance of
JsonPointer.RefToken. - Throws:
IndexOutOfBoundsException- The specified index is illegal.
-
last
public io.fabric8.zjsonpatch.JsonPointer.RefToken last()
Retrieves the last reference token for this JSON pointer.- Returns:
- The last
JsonPointer.RefTokencomprising this instance. - Throws:
IllegalStateException- Last cannot be called onrootpointers.
-
getParent
public JsonPointer getParent()
Creates a JSON pointer to the parent of the node represented by this instance. The parent of therootpointer is the root pointer itself.- Returns:
- A
JsonPointerto the parent node.
-
evaluate
public com.fasterxml.jackson.databind.JsonNode evaluate(com.fasterxml.jackson.databind.JsonNode document) throws JsonPointerEvaluationExceptionTakes a target document and resolves the node represented by this instance. The evaluation semantics are described in RFC 6901 sectino 4.- Parameters:
document- The target document against which to evaluate the JSON pointer.- Returns:
- The
JsonNoderesolved by evaluating this JSON pointer. - Throws:
JsonPointerEvaluationException- The pointer could not be evaluated.
-
-