Search in sources :

Example 36 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testAddAt.

public void testAddAt() {
    Json json = Json.list(1, 3);
    json.addAt(1, 2);
    assertEquals(3, json.size());
    assertEquals(1, json.at(0).asInt());
    assertEquals(2, json.at(1).asInt());
    assertEquals(3, json.at(2).asInt());
}
Also used : Json(siena.Json)

Example 37 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testRemoveAt.

public void testRemoveAt() {
    Json json = Json.list(1, 2, 3);
    json.removeAt(1);
    assertEquals(2, json.size());
    assertEquals(1, json.at(0).asInt());
    assertEquals(3, json.at(1).asInt());
}
Also used : Json(siena.Json)

Example 38 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testBuildEmptyList.

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

Example 39 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method sumInteger.

public void sumInteger() {
    Json map1 = Json.map().put("a", 1);
    map1.sumInteger("a", 2);
    assertEquals(3, map1.get("a").asInt());
    map1 = Json.map();
    map1.sumInteger("a", 2);
    assertEquals(2, map1.get("a").asInt());
}
Also used : Json(siena.Json)

Example 40 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testSortedMap2.

public void testSortedMap2() {
    Json json = Json.sortedMap().put("2009-01", 1).put("2008-10", 400);
    Iterator<String> keys = json.keys().iterator();
    assertEquals("2008-10", keys.next());
    assertEquals("2009-01", keys.next());
}
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