Class Jackson3JsonPointer
java.lang.Object
com.flipkart.zjsonpatch.AbstractJsonPointer
com.flipkart.zjsonpatch.Jackson3JsonPointer
Implements RFC 6901 (JSON Pointer)
For full details, please refer to RFC 6901.
Generally, a JSON Pointer is a string representation of a path into a JSON document. This class implements the RFC as closely as possible, and offers several helpers and utility methods on top of it:
// Parse, build or render a JSON pointer
String path = "/a/0/b/1";
Jackson3JsonPointer ptr1 = Jackson3JsonPointer.parse(java.lang.String)(path);
Jackson3JsonPointer ptr2 = Jackson3JsonPointer.ROOT.append("a").append(0).append("b").append(1);
assert(ptr1.equals(ptr2));
assert(path.equals(ptr1.toString()));
assert(path.equals(ptr2.toString()));
// Evaluate a JSON pointer against a live document
ObjectMapper om = new ObjectMapper();
JsonNode doc = om.readTree("{\"foo\":[\"bar\", \"baz\"]}");
JsonNode baz = Jackson3JsonPointer.parse("/foo/1").evaluate(doc);
assert(baz.stringValue().equals("baz"));
Instances of Jackson3JsonPointer and its constituent RefTokens are immutable.
- Since:
- 0.6.0
- Author:
- Mariusz Sondecki
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Jackson3JsonPointerA JSON pointer representing the root node of a JSON document -
Constructor Summary
ConstructorsConstructorDescriptionJackson3JsonPointer(List<RefToken> tokens) Constructs a new pointer from a list of reference tokens. -
Method Summary
Modifier and TypeMethodDescriptionprotected Jackson3JsonPointercreateInstance(RefToken[] tokens) tools.jackson.databind.JsonNodeevaluate(tools.jackson.databind.JsonNode document) Takes a target document and resolves the node represented by this instance.Creates a JSON pointer to the parent of the node represented by this instance.static Jackson3JsonPointerParses a valid string representation of a JSON Pointer.Methods inherited from class com.flipkart.zjsonpatch.AbstractJsonPointer
decompose, equals, get, getTokens, hashCode, isRoot, last, parseTokens, toString
-
Field Details
-
ROOT
A JSON pointer representing the root node of a JSON document
-
-
Constructor Details
-
Jackson3JsonPointer
-
-
Method Details
-
parse
Parses a valid string representation of a JSON Pointer.- Parameters:
path- The string representation to be parsed.- Returns:
- An instance of
Jackson3JsonPointerconforming to the specified string representation. - Throws:
IllegalArgumentException- The specified JSON Pointer is invalid.
-
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
Jackson3JsonPointerto the parent node.
-
evaluate
public tools.jackson.databind.JsonNode evaluate(tools.jackson.databind.JsonNode document) throws JsonPointerEvaluationException Takes a target document and resolves the node represented by this instance. The evaluation semantics are described in RFC 6901 section 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.
-
createInstance
- Specified by:
createInstancein classAbstractJsonPointer
-