X Tutup
Skip to content

Commit 5223aad

Browse files
committed
added some javadoc to JSONPointer
1 parent 45bd72c commit 5223aad

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

JSONPointer.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@
88
import java.util.ArrayList;
99
import java.util.List;
1010

11+
/**
12+
* A JSON Pointer is a simple query language defined for JSON documents by
13+
* <a href="https://tools.ietf.org/html/rfc6901">RFC 6901</a>.
14+
*/
1115
public class JSONPointer {
1216

1317
private List<String> refTokens;
1418

19+
/**
20+
* Pre-parses and initializes a new {@code JSONPointer} instance. If you want to
21+
* evaluate the same JSON Pointer on different JSON documents then it is recommended
22+
* to keep the {@code JSONPointer} instances due to performance considerations.
23+
*
24+
* @param pointer the JSON String or URI Fragment representation of the JSON pointer.
25+
* @throws IllegalArgumentException if {@code pointer} is not a valid JSON pointer
26+
*/
1527
public JSONPointer(String pointer) {
1628
if (pointer == null) {
1729
throw new NullPointerException("pointer cannot be null");
@@ -44,6 +56,16 @@ private String unescape(String token) {
4456
.replace("\\\\", "\\");
4557
}
4658

59+
/**
60+
* Evaluates this JSON Pointer on the given {@code document}. The {@code document}
61+
* is usually a {@link JSONObject} or a {@link JSONArray} instance, but the empty
62+
* JSON Pointer ({@code ""}) can be evaluated on any JSON values and in such case the
63+
* returned value will be {@code document} itself.
64+
*
65+
* @param document the JSON document which should be the subject of querying.
66+
* @return the result of the evaluation
67+
* @throws JSONPointerException if an error occurs during evaluation
68+
*/
4769
public Object queryFrom(Object document) {
4870
if (refTokens.isEmpty()) {
4971
return document;

0 commit comments

Comments
 (0)
X Tutup