public class JSONPointer
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
JSONPointer.Builder
This class allows the user to build a JSONPointer in steps, using exactly one segment in each step.
|
Constructor and Description |
---|
JSONPointer(java.util.List<java.lang.String> refTokens) |
JSONPointer(java.lang.String pointer)
Pre-parses and initializes a new
JSONPointer instance. |
Modifier and Type | Method and Description |
---|---|
static JSONPointer.Builder |
builder()
Static factory method for
JSONPointer.Builder . |
java.lang.Object |
queryFrom(java.lang.Object document)
Evaluates this JSON Pointer on the given
document . |
java.lang.String |
toString()
Returns a string representing the JSONPointer path value using string representation
|
java.lang.String |
toURIFragment()
Returns a string representing the JSONPointer path value using URI fragment identifier representation
|
public JSONPointer(java.lang.String pointer)
JSONPointer
instance. If you want to evaluate the same JSON Pointer on
different JSON documents then it is recommended to keep the JSONPointer
instances due to performance
considerations.pointer
- the JSON String or URI Fragment representation of the JSON pointer.java.lang.IllegalArgumentException
- if pointer
is not a valid JSON pointerpublic JSONPointer(java.util.List<java.lang.String> refTokens)
public static JSONPointer.Builder builder()
JSONPointer.Builder
. Example usage:
JSONPointer pointer = JSONPointer.builder()
.append("obj")
.append("other~key").append("another/key")
.append("\"")
.append(0)
.build();
JSONPointer
instance by chained
JSONPointer.Builder.append(String)
calls.public java.lang.Object queryFrom(java.lang.Object document) throws JSONPointerException
document
. The document
is usually a JSONObject
or a
JSONArray
instance, but the empty JSON Pointer (""
) can be evaluated on any JSON values and in such
case the returned value will be document
itself.document
- the JSON document which should be the subject of querying.JSONPointerException
- if an error occurs during evaluationpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toURIFragment()