Search in sources :

Example 11 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testFind.

public void testFind() {
    Json data = map().put("foo", list(1, 2, list(1, 2, map().put("bar", 1))));
    Json result = data.find("foo", 2, 2, "bar");
    assertNotNull(result);
    assertEquals(1, result.asInt());
    // try to call at() in a map
    result = data.find(1);
    assertNull(result);
    // try to call get() in a list
    result = data.find("foo", "bar");
    assertNull(result);
    // key not found in map
    result = data.find("bar", "baz");
    assertNull(result);
    // out of bounds
    result = data.find("foo", 3);
    assertNull(result);
}
Also used : Json(siena.Json)

Example 12 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testArray.

public void testArray() {
    Json list = new Json(new Object[] { 1, 2, 3 });
    assertEquals(3, list.size());
    assertEquals(1, list.at(0).asInt());
    assertEquals(2, list.at(1).asInt());
    assertEquals(3, list.at(2).asInt());
    assertEquals("[1, 2, 3]", list.toString());
}
Also used : Json(siena.Json)

Example 13 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testEscapeCharacters.

public void testEscapeCharacters() {
    Json json = Json.loads("[\"\\b\\f\\n\\r\\t\\\"\\/\\u0041\"]");
    assertTrue(json.isList());
    assertEquals(1, json.size());
    assertTrue(json.at(0).isString());
    assertEquals("[\"\\b\\f\\n\\r\\t\\\"\\/A\"]", json.toString());
}
Also used : Json(siena.Json)

Example 14 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testBuildString.

public void testBuildString() {
    Json json = new Json("foobar");
    assertTrue(json.isString());
    assertFalse(json.isBoolean());
    assertFalse(json.isList());
    assertFalse(json.isMap());
    assertFalse(json.isEmpty());
    assertEquals(1, json.size());
    assertEquals("\"foobar\"", json.toString());
}
Also used : Json(siena.Json)

Example 15 with Json

use of siena.Json in project siena by mandubian.

the class JsonTest method testEnumerations.

public void testEnumerations() {
    Json data = list(Gender.MALE);
    assertEquals("[\"MALE\"]", data.toString());
    assertEquals(Gender.MALE.name(), data.at(0).str());
}
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