An example of using JSON Pointer to query JSON node.
JsonReader reader =Json.createReader(JsonpTest.class.getResourceAsStream("/persons.json"));JsonArray arrays =reader.readArray();JsonPointer p =Json.createPointer("/0/name");JsonValue name =p.getValue(arrays);System.out.println("json value ::"+ name);
An example of using JSON Patch to update some JSON nodes.
JsonReader reader =Json.createReader(JsonpTest.class.getResourceAsStream("/persons.json"));JsonArray jsonaArray =reader.readArray();JsonPatch patch =Json.createPatchBuilder() .replace("/0/name","Duke Oracle").remove("/1").build();JsonArray result =patch.apply(jsonaArray);System.out.println(result.toString());Type type =newArrayList<Person>() {}.getClass().getGenericSuperclass();List<Person> person =JsonbBuilder.create().fromJson(result.toString(), type);assertEquals("Duke Oracle",person.get(0).getName());
They are very useful to patch the existing entity when add HTTP Patch method support in RESTful APIs, we will demonstrate this later in JAX-RS.
Grab the source codes from my GitHub account, and have a try.