use of siena.Json in project siena by mandubian.
the class JsonTest method testParseMap.
public void testParseMap() {
Json json = Json.loads("{\"foo\": 1234, \"bar\": true}");
assertTrue(json.isMap());
assertEquals(2, json.size());
Json foo = json.get("foo");
assertTrue(foo.isNumber());
assertEquals(1234, foo.asInt());
Json bar = json.get("bar");
assertTrue(bar.isBoolean());
assertEquals(true, bar.asBoolean());
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testBuildComplex.
public void testBuildComplex() {
Json json = Json.list(1, 2, 3, 4, true, false, null, Json.map().put("foo", 1).put("bar", 2));
assertEquals(1, json.at(0).asInt());
assertEquals(2, json.at(1).asInt());
assertEquals(3, json.at(2).asInt());
assertEquals(4, json.at(3).asInt());
assertTrue(json.at(4).asBoolean());
assertFalse(json.at(5).asBoolean());
assertTrue(json.at(6).isNull());
assertTrue(json.at(7).isMap());
assertEquals(2, json.at(7).size());
assertEquals(1, json.at(7).get("foo").asInt());
assertEquals(2, json.at(7).get("bar").asInt());
}
use of siena.Json in project siena by mandubian.
the class JsonTest method sumReal.
public void sumReal() {
Json map1 = Json.map().put("a", 1.5);
map1.sumReal("a", 2.5);
assertEquals(4, map1.get("a").asInt());
map1 = Json.map();
map1.sumReal("a", 2.5);
assertEquals(2.5, map1.get("a").asInt());
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testPutComplex.
public void testPutComplex() {
List<Integer> list1 = Arrays.asList(new Integer[] { 1, 2, 3 });
List<String> list2 = Arrays.asList(new String[] { "foo", "bar", "baz" });
List<List<?>> objects = new ArrayList<List<?>>();
;
objects.add(list1);
objects.add(list2);
Json map = Json.map().put("foo", objects);
Json list = map.get("foo");
assertEquals(2, list.size());
assertEquals(3, list.at(0).size());
assertEquals(1, list.at(0).at(0).asInt());
assertEquals(2, list.at(0).at(1).asInt());
assertEquals(3, list.at(0).at(2).asInt());
assertEquals(3, list.at(1).size());
assertEquals("foo", list.at(1).at(0).str());
assertEquals("bar", list.at(1).at(1).str());
assertEquals("baz", list.at(1).at(2).str());
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testSortedMap.
public void testSortedMap() {
Json json = Json.sortedMap().put("1", 1).put("400", 400).put("3", 3).put("2", 2);
Iterator<String> keys = json.keys().iterator();
assertEquals("1", keys.next());
assertEquals("2", keys.next());
assertEquals("3", keys.next());
assertEquals("400", keys.next());
}
Aggregations