Search in sources :

Example 11 with JsonPointer

use of io.vertx.core.json.pointer.JsonPointer in project vert.x by eclipse.

the class JsonPointerTest method testParsing.

@Test
public void testParsing() {
    JsonPointer pointer = JsonPointer.from("/hello/world");
    assertEquals("/hello/world", pointer.toString());
}
Also used : JsonPointer(io.vertx.core.json.pointer.JsonPointer) Test(org.junit.Test)

Example 12 with JsonPointer

use of io.vertx.core.json.pointer.JsonPointer in project vert.x by eclipse.

the class JsonPointerTest method testTracedQuery.

@Test
public void testTracedQuery() {
    JsonObject child2 = new JsonObject().put("child3", 1);
    JsonArray child1 = new JsonArray().add(child2);
    JsonObject root = new JsonObject().put("child1", child1);
    JsonPointer pointer = JsonPointer.create().append("child1").append("0").append("child3");
    List<Object> traced = pointer.tracedQuery(root, JsonPointerIterator.JSON_ITERATOR);
    assertEquals(4, traced.size());
    assertSame(root, traced.get(0));
    assertSame(child1, traced.get(1));
    assertSame(child2, traced.get(2));
    assertEquals(1, traced.get(3));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) JsonPointer(io.vertx.core.json.pointer.JsonPointer) Test(org.junit.Test)

Example 13 with JsonPointer

use of io.vertx.core.json.pointer.JsonPointer in project vert.x by eclipse.

the class JsonPointerExamples method example1Pointers.

public void example1Pointers() {
    // Build a pointer from a string
    JsonPointer pointer1 = JsonPointer.from("/hello/world");
    // Build a pointer manually
    JsonPointer pointer2 = JsonPointer.create().append("hello").append("world");
}
Also used : JsonPointer(io.vertx.core.json.pointer.JsonPointer)

Example 14 with JsonPointer

use of io.vertx.core.json.pointer.JsonPointer in project vert.x by eclipse.

the class JsonPointerTest method testIsParent.

@Test
public void testIsParent() {
    JsonPointer parent = JsonPointer.fromURI(URI.create("yaml/valid/refs/Circular.yaml#/properties"));
    JsonPointer child = JsonPointer.fromURI(URI.create("yaml/valid/refs/Circular.yaml#/properties/parent"));
    assertTrue(parent.isParent(child));
    assertFalse(child.isParent(parent));
}
Also used : JsonPointer(io.vertx.core.json.pointer.JsonPointer) Test(org.junit.Test)

Example 15 with JsonPointer

use of io.vertx.core.json.pointer.JsonPointer in project vert.x by eclipse.

the class JsonPointerTest method testWrongUsageOfDashForQuerying.

@Test
public void testWrongUsageOfDashForQuerying() {
    JsonArray array = new JsonArray();
    array.add(new JsonObject().put("hello", new JsonObject().put("world", 2).put("worl", "wrong")).put("helo", new JsonObject().put("world", "wrong").put("worl", "wrong")));
    array.add(new JsonObject().put("hello", new JsonObject().put("world", 1).put("worl", "wrong")).put("helo", new JsonObject().put("world", "wrong").put("worl", "wrong")));
    JsonPointer pointer = JsonPointer.from("/-/hello/world");
    assertNull(pointer.queryJson(array));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonPointer(io.vertx.core.json.pointer.JsonPointer) Test(org.junit.Test)

Aggregations

JsonPointer (io.vertx.core.json.pointer.JsonPointer)24 Test (org.junit.Test)23 JsonObject (io.vertx.core.json.JsonObject)8 JsonArray (io.vertx.core.json.JsonArray)5 ArrayList (java.util.ArrayList)1