mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
added some javadoc to JSONPointer
This commit is contained in:
parent
45bd72c15d
commit
5223aadd67
1 changed files with 22 additions and 0 deletions
|
@ -8,10 +8,22 @@ import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JSON Pointer is a simple query language defined for JSON documents by
|
||||||
|
* <a href="https://tools.ietf.org/html/rfc6901">RFC 6901</a>.
|
||||||
|
*/
|
||||||
public class JSONPointer {
|
public class JSONPointer {
|
||||||
|
|
||||||
private List<String> refTokens;
|
private List<String> refTokens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-parses and initializes a new {@code JSONPointer} instance. If you want to
|
||||||
|
* evaluate the same JSON Pointer on different JSON documents then it is recommended
|
||||||
|
* to keep the {@code JSONPointer} instances due to performance considerations.
|
||||||
|
*
|
||||||
|
* @param pointer the JSON String or URI Fragment representation of the JSON pointer.
|
||||||
|
* @throws IllegalArgumentException if {@code pointer} is not a valid JSON pointer
|
||||||
|
*/
|
||||||
public JSONPointer(String pointer) {
|
public JSONPointer(String pointer) {
|
||||||
if (pointer == null) {
|
if (pointer == null) {
|
||||||
throw new NullPointerException("pointer cannot be null");
|
throw new NullPointerException("pointer cannot be null");
|
||||||
|
@ -44,6 +56,16 @@ public class JSONPointer {
|
||||||
.replace("\\\\", "\\");
|
.replace("\\\\", "\\");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluates this JSON Pointer on the given {@code document}. The {@code document}
|
||||||
|
* is usually a {@link JSONObject} or a {@link JSONArray} instance, but the empty
|
||||||
|
* JSON Pointer ({@code ""}) can be evaluated on any JSON values and in such case the
|
||||||
|
* returned value will be {@code document} itself.
|
||||||
|
*
|
||||||
|
* @param document the JSON document which should be the subject of querying.
|
||||||
|
* @return the result of the evaluation
|
||||||
|
* @throws JSONPointerException if an error occurs during evaluation
|
||||||
|
*/
|
||||||
public Object queryFrom(Object document) {
|
public Object queryFrom(Object document) {
|
||||||
if (refTokens.isEmpty()) {
|
if (refTokens.isEmpty()) {
|
||||||
return document;
|
return document;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue