use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testCreateFromMapNestedJsonArray.
@Test
public void testCreateFromMapNestedJsonArray() {
Map<String, Object> map = new HashMap<>();
JsonArray nestedArr = new JsonArray().add("foo");
map.put("nested", nestedArr);
JsonObject obj = new JsonObject(map);
JsonArray nestedRetrieved = obj.getJsonArray("nested");
assertEquals("foo", nestedRetrieved.getString(0));
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method assertNumberNotEquals.
private void assertNumberNotEquals(Number value1, Number value2) {
JsonObject o1 = new JsonObject().put("key", value1);
JsonObject o2 = new JsonObject().put("key", value2);
if (o1.equals(o2)) {
fail("Was expecting " + value1.getClass().getSimpleName() + ":" + value1 + " != " + value2.getClass().getSimpleName() + ":" + value2);
}
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testCommentsInJson.
// Strict JSON doesn't allow comments but we do so users can add comments to config files etc
@Test
public void testCommentsInJson() {
String jsonWithComments = "// single line comment\n" + "/*\n" + " This is a multi \n" + " line comment\n" + "*/\n" + "{\n" + "// another single line comment this time inside the JSON object itself\n" + " \"foo\": \"bar\" // and a single line comment at end of line \n" + "/*\n" + " This is a another multi \n" + " line comment this time inside the JSON object itself\n" + "*/\n" + "}";
JsonObject json = new JsonObject(jsonWithComments);
assertEquals("{\"foo\":\"bar\"}", json.encode());
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testMergeIn1.
@Test
public void testMergeIn1() {
JsonObject obj1 = new JsonObject().put("foo", "bar");
JsonObject obj2 = new JsonObject().put("eek", "flurb");
obj1.mergeIn(obj2);
assertEquals(2, obj1.size());
assertEquals("bar", obj1.getString("foo"));
assertEquals("flurb", obj1.getString("eek"));
assertEquals(1, obj2.size());
assertEquals("flurb", obj2.getString("eek"));
}
use of io.vertx.core.json.JsonObject in project vert.x by eclipse.
the class JsonObjectTest method testStream.
@Test
public void testStream() {
jsonObject.put("foo", "bar");
jsonObject.put("quux", 123);
JsonObject obj = createJsonObject();
jsonObject.put("wibble", obj);
List<Map.Entry<String, Object>> list = jsonObject.stream().collect(Collectors.toList());
Iterator<Map.Entry<String, Object>> iter = list.iterator();
assertTrue(iter.hasNext());
Map.Entry<String, Object> entry = iter.next();
assertEquals("foo", entry.getKey());
assertEquals("bar", entry.getValue());
assertTrue(iter.hasNext());
entry = iter.next();
assertEquals("quux", entry.getKey());
assertEquals(123, entry.getValue());
assertTrue(iter.hasNext());
entry = iter.next();
assertEquals("wibble", entry.getKey());
assertEquals(obj, entry.getValue());
assertFalse(iter.hasNext());
}
Aggregations