javax.json.JsonPointer Java Examples

The following examples show how to use javax.json.JsonPointer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserView.java    From javaee8-cookbook with Apache License 2.0 7 votes vote down vote up
private void loadFromStructure() {
    JsonStructure structure = BUILDERFACTORY.createObjectBuilder()
            .add("name", "User1")
            .add("email", "[email protected]")
            .add("profiles", BUILDERFACTORY.createArrayBuilder()
                    .add(BUILDERFACTORY.createObjectBuilder()
                            .add("id", "1")
                            .add("name", "Profile1"))
                    .add(BUILDERFACTORY.createObjectBuilder()
                            .add("id", "2")
                            .add("name", "Profile2")))
            .build();
    fromStructure = jsonbBuilder.toJson(structure);

    JsonPointer pointer = Json.createPointer("/profiles");
    JsonValue value = pointer.getValue(structure);
    fromJpointer = value.toString();
}
 
Example #2
Source File: JsonpTest.java    From ee8-sandbox with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: QuotesResource.java    From blog-tutorials with MIT License 5 votes vote down vote up
@GET
@Metered
@Produces(MediaType.APPLICATION_JSON)
public Response getQuoteOfTheDay() {

  JsonObject quoteOfTheDay = quotesClient.getQuoteOfTheDay();
  JsonPointer quotePointer = Json.createPointer("/contents/quotes/0/quote");
  JsonObject result = Json.createObjectBuilder()
    .add("quoteOfTheDay", quotePointer.getValue(quoteOfTheDay)).build();

  return Response.ok(result).build();
}
 
Example #4
Source File: JPointer.java    From javaee8-cookbook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    try (InputStream is = JPointer.class.getClassLoader().getResourceAsStream("user.json");
            JsonReader jr = Json.createReader(is)) {

        JsonStructure js = jr.read();
        JsonPointer jp = Json.createPointer("/user/profile");
        JsonValue jv = jp.getValue(js);
        System.out.println("profile: " + jv);

    }
}
 
Example #5
Source File: JsonPointerCrud.java    From tutorials with MIT License 5 votes vote down vote up
public JsonStructure update(String key, String newValue) {

        JsonPointer jsonPointer = Json.createPointer("/" + key);
        JsonString jsonNewValue = Json.createValue(newValue);
        jsonStructure = jsonPointer.replace(jsonStructure, jsonNewValue);

        return jsonStructure;
    }
 
Example #6
Source File: PreComputedJsonpProvider.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public JsonPointer createPointer(final String path) {
    return jsonpProvider.createPointer(path);
}
 
Example #7
Source File: VisibilityService.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
private JsonPointer toPointer(final String absoluteTargetPath) {
    return jsonProvider.createPointer('/' + absoluteTargetPath.replace('.', '/'));
}
 
Example #8
Source File: ConfigurableBus.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
@Override
public JsonPointer createPointer(final String path) {
    return provider.createPointer(path);
}
 
Example #9
Source File: JsonPointerCrud.java    From tutorials with MIT License 4 votes vote down vote up
public String fetchValueFromKey(String key) {
    JsonPointer jsonPointer = Json.createPointer("/" + key);
    JsonString jsonString = (JsonString) jsonPointer.getValue(jsonStructure);

    return jsonString.getString();
}
 
Example #10
Source File: JsonPointerCrud.java    From tutorials with MIT License 4 votes vote down vote up
public String fetchListValues(String key) {
    JsonPointer jsonPointer = Json.createPointer("/" + key);
    JsonObject jsonObject = (JsonObject) jsonPointer.getValue(jsonStructure);

    return jsonObject.toString();
}
 
Example #11
Source File: JsonPointerCrud.java    From tutorials with MIT License 4 votes vote down vote up
public boolean check(String key) {
    JsonPointer jsonPointer = Json.createPointer("/" + key);
    boolean found = jsonPointer.containsValue(jsonStructure);

    return found;
}
 
Example #12
Source File: JsonPointerCrud.java    From tutorials with MIT License 3 votes vote down vote up
public JsonStructure insert(String key, String value) {

        JsonPointer jsonPointer = Json.createPointer("/" + key);
        JsonString jsonValue = Json.createValue(value);
        jsonStructure = jsonPointer.add(jsonStructure, jsonValue);

        return jsonStructure;

    }
 
Example #13
Source File: JsonPointerCrud.java    From tutorials with MIT License 3 votes vote down vote up
public JsonStructure delete(String key) {

        JsonPointer jsonPointer = Json.createPointer("/" + key);
        jsonPointer.getValue(jsonStructure);
        jsonStructure = jsonPointer.remove(jsonStructure);

        return jsonStructure;

    }
 
Example #14
Source File: JsonPointerCrud.java    From tutorials with MIT License 3 votes vote down vote up
public String fetchFullJSON() {
    JsonPointer jsonPointer = Json.createPointer("");
    JsonObject jsonObject = (JsonObject) jsonPointer.getValue(jsonStructure);

    return jsonObject.toString();

}