Search in sources :

Example 16 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testSumDoubles.

public void testSumDoubles() {
    Json map1 = Json.map().put("a", 1.5);
    Json map2 = Json.map().put("a", 2.5).put("b", 5);
    map1.sumReals(map2);
    assertEquals(4, map1.get("a").asInt());
    assertEquals(5, map1.get("b").asInt());
}
Also used : Json(siena.Json)

Example 17 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testIndexOf.

public void testIndexOf() {
    Json json = Json.list(1, 2, 3, "hello", true, false, null);
    assertEquals(0, json.indexOf(1));
    assertEquals(1, json.indexOf(2));
    assertEquals(2, json.indexOf(3));
    assertEquals(3, json.indexOf("hello"));
    assertEquals(4, json.indexOf(true));
    assertEquals(5, json.indexOf(false));
    assertEquals(6, json.indexOf(null));
}
Also used : Json(siena.Json)

Example 18 with Json

use of siena.Json in project siena by mandubian.

the class User method testSimple.

public void testSimple() throws Exception {
    Date date = createDate();
    Json data = JsonSerializer.serialize(new Contact("Alberto", "Gimeno", Gender.MALE, date, date));
    Contact contact = (Contact) JsonSerializer.deserialize(Contact.class, data);
    assertEquals("Alberto", contact.firstName);
    assertNull(contact.foo);
    assertEquals("Gimeno", contact.lastName);
    assertEquals(Gender.MALE, contact.gender);
    assertEquals(date, contact.birthday);
    assertEquals(date, contact.rebirthday);
}
Also used : Json(siena.Json) Date(java.util.Date)

Example 19 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testRemoveAll.

public void testRemoveAll() {
    Json list = Json.list(1, 2, 3);
    list.removeAll(Json.list(1, 2));
    assertEquals(1, list.size());
    assertEquals(3, list.at(0).asInt());
    Json map = Json.map().put("foo", 1).put("bar", 2);
    map.removeAll(Json.map().put("foo", 1));
    assertEquals(1, map.size());
    assertEquals(2, map.get("bar").asInt());
}
Also used : Json(siena.Json)

Example 20 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testBuildEmptyMap.

public void testBuildEmptyMap() {
    Json json = Json.map();
    assertTrue(json.isMap());
    assertTrue(json.isEmpty());
    assertFalse(json.isBoolean());
    assertFalse(json.isList());
    assertFalse(json.isNumber());
    assertFalse(json.isString());
    assertEquals(0, json.size());
    assertEquals("{}", json.toString());
}
Also used : Json(siena.Json)

Aggregations

Json (siena.Json)48 SienaException (siena.SienaException)7 Field (java.lang.reflect.Field)6 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 Date (java.util.Date)3 Element (org.dom4j.Element)3 DecimalPrecision (siena.core.DecimalPrecision)3 BufferedReader (java.io.BufferedReader)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectOutput (java.io.ObjectOutput)2 ObjectOutputStream (java.io.ObjectOutputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Polymorphic (siena.core.Polymorphic)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1