File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 88import java .util .ArrayList ;
99import 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+ */
1115public 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 ;
You can’t perform that action at this time.
0 commit comments