use of siena.Json in project siena by mandubian.
the class User method testMultiple.
@SuppressWarnings("unchecked")
public void testMultiple() throws Exception {
Date date = createDate();
Map<String, Contact> contacts = new HashMap<String, Contact>();
contacts.put("id1", new Contact("Alberto", "Gimeno", Gender.MALE, date, date));
Json data = JsonSerializer.serialize(contacts);
contacts = (Map<String, Contact>) JsonSerializer.deserialize(Util.getField(User.class, "contacts"), data);
Contact contact = contacts.get("id1");
assertEquals("Alberto", contact.firstName);
assertNull(contact.foo);
assertEquals("Gimeno", contact.lastName);
assertEquals(Gender.MALE, contact.gender);
assertEquals(date, contact.birthday);
assertEquals(date, contact.rebirthday);
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testFormatAndParseNumbers.
public void testFormatAndParseNumbers() {
Json json = Json.loads("[1.0, 2.0, 3, 4, 5, 6.1, 1.0e12, 2e12]");
String s = json.toString();
assertTrue(s.contains("1.0"));
assertTrue(s.contains("2.0"));
assertFalse(s.contains("3.0"));
assertFalse(s.contains("4.0"));
assertFalse(s.contains("5.0"));
assertTrue(s.contains("6.1"));
assertTrue(s.contains("1.0E12"));
assertTrue(s.contains("2.0E12"));
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testContains.
public void testContains() {
Json json = Json.list(1, 2, 3);
assertTrue(json.contains(1));
assertTrue(json.contains(2));
assertTrue(json.contains(3));
assertFalse(json.contains(4));
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testParseComplex.
public void testParseComplex() {
Json json = null;
json = Json.loads("{}");
assertEquals("{}", json.toString());
json = Json.loads("[{}]");
assertEquals("[{}]", json.toString());
json = Json.loads("{}");
assertEquals("{}", json.toString());
json = Json.loads("[{}, {}, {}]");
assertEquals("[{}, {}, {}]", json.toString());
json = Json.loads("{\"foo\": 1234, \"bar\": [1, 2, 3, [{}], true, false, null, {}]}");
assertTrue(json.isMap());
assertEquals(2, json.size());
assertEquals(1234, json.get("foo").asInt());
Json list = json.get("bar");
assertTrue(list.isList());
assertEquals(8, list.size());
assertEquals(1, list.at(0).asInt());
assertEquals(2, list.at(1).asInt());
assertEquals(3, list.at(2).asInt());
assertTrue(list.at(3).isList());
assertEquals(1, list.at(3).size());
assertTrue(list.at(3).at(0).isMap());
assertTrue(list.at(3).at(0).isEmpty());
assertTrue(list.at(4).asBoolean());
assertFalse(list.at(5).asBoolean());
assertTrue(list.at(6).isNull());
assertTrue(list.at(7).isMap());
assertTrue(list.at(7).isEmpty());
}
use of siena.Json in project siena by mandubian.
the class JsonTest method testMap.
public void testMap() {
Map<String, Object> m = new HashMap<String, Object>();
m.put("foo", 1);
Json map = new Json(m);
assertTrue(map.isMap());
assertEquals(1, map.size());
assertEquals(1, map.get("foo").asInt());
assertEquals("{\"foo\": 1}", map.toString());
}
Aggregations