public void findCustomerByAddress() { searchResult = null; String text = "/" + this.addressSearchText; JsonObject json = Json.createObjectBuilder().build(); JsonValue object = json.getJsonObject(fetchJson()); if (addressSearchText != null) { JsonPointer pointer = Json.createPointer(text); JsonValue result = pointer.getValue(object.asJsonArray()); // Replace a value JsonArray array = (JsonArray) pointer.replace(object.asJsonArray(), Json.createValue("1000 JsonP Drive")); searchResult = array.toString(); //searchResult = result.toString(); } }
@Test public void testJsonPointer() { 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); // assertEquals("Duke", name.toString()); JsonReader objReader = Json.createReader(JsonpTest.class.getResourceAsStream("/person.json")); JsonPointer p2 = Json.createPointer("/name"); JsonValue name2 = p2.getValue(objReader.readObject()); System.out.println("json value ::" + name2); // assertEquals("Duke", name2.toString()); }
@Override public JsonPointer createPointer(String path) { return DELEGATE.createPointer(path); }
@Override public JsonPointer createPointer(String path) { return new JsonPointerImpl(path); }