Examples of Json


Examples of siena.Json

    map.putDefault("a", 3);
    assertEquals(2, map.get("a").asInt());
  }
 
  public void testEqualsTo() {
    Json a = map();
    Json b = map();
    assertTrue(a.equalsTo(b));

    a = list();
    b = list();
    assertTrue(a.equalsTo(b));

    a = list("foo", "bar");
    b = list("foo", "bar");
    assertTrue(a.equalsTo(b));
   
    a = map().put("foo", "bar");
    b = map().put("foo", "bar");
    assertTrue(a.equalsTo(b));
   
    a = map().put("foo", list("bar"));
    b = map().put("foo", list("bar"));
    assertTrue(a.equalsTo(b));
   
    a = map();
    b = sortedMap();
    assertTrue(a.equalsTo(b));
   
    a = new Json(true);
    b = new Json(true);
    assertTrue(a.equalsTo(b));
   
    a = new Json(1);
    b = new Json(1l);
    assertTrue(a.equalsTo(b));
   
    a = new Json(1.0);
    b = new Json(1l);
    assertTrue(a.equalsTo(b));
   
    a = new Json(null);
    b = new Json(null);
    assertTrue(a.equalsTo(b));

    a = map();
    b = list();
    assertFalse(a.equalsTo(b));

    a = list();
    b = map();
    assertFalse(a.equalsTo(b));
   
    a = list(1, 2, 3, 4);
    b = list(1, 2, 3);
    assertFalse(a.equalsTo(b));
   
    a = map().put("foo", 1);
    b = map().put("bar", 1);
    assertFalse(a.equalsTo(b));
   
    a = new Json(1);
    b = new Json(null);
    assertFalse(a.equalsTo(b));
   
    a = list(1, 3);
    b = list(1, 2);
    assertFalse(a.equalsTo(b));
View Full Code Here

Examples of siena.Json

    b = a;
    assertTrue(a.equalsTo(b));
  }
 
  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);
   
View Full Code Here

Examples of siena.Json

    result = data.find("foo", 3);
    assertNull(result);
  }
 
  public void testEnumerations() {
    Json data = list(Gender.MALE);
    assertEquals("[\"MALE\"]", data.toString());
    assertEquals(Gender.MALE.name(), data.at(0).str());
  }
View Full Code Here

Examples of siena.Json

public class JsonSerializer implements Serializer {

  public Document deserialize(InputStream in) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    Json json = Json.load(reader);
    return fromJson(json);
  }
View Full Code Here

Examples of siena.Json

    return fromJson(json);
  }

  public void serialize(Document document, OutputStream out)
      throws IOException {
    Json json = toJson(document);
    json.write(new OutputStreamWriter(out));
  }
View Full Code Here

Examples of siena.Json

    Json json = toJson(document);
    json.write(new OutputStreamWriter(out));
  }
 
  private static Json toJson(Document doc) {
    Json json = Json.map();
    Element root = doc.getRootElement();
    Json map = Json.map();
    json.put(root.getName(), map);
    toJson(root, map);
    return json;
  }
View Full Code Here

Examples of siena.Json

        e.put("@", element.getText());
//      } else {
//        e.put("@", null);
      }
    } else {
      Json map = Json.map();
      e.put("@", map);
      for (Element elem : elements) {
        Json j = Json.map();
        map.put(elem.getName(), j);
        toJson(elem, j);
      }
    }
   
View Full Code Here

Examples of siena.Json

 
  private static void fromJson(Json json, Element element) {
    Set<String> keys = json.keys();
    for (String key : keys) {
      if("@".equals(key)) {
        Json value = json.get(key);
        if(value.isString()) {
          element.setText(value.str());
        } else {
          Set<String> ks = value.keys();
          for (String k : ks) {
            Element child = element.addElement(k);
            fromJson(value.get(k), child);
          }
        }
      } else {
        element.addAttribute(key, json.get(key).str());
      }
View Full Code Here

Examples of siena.Json

   
    System.out.println("Original document");
    System.out.println(doc.asXML());
    System.out.println();
   
    Json json = toJson(doc);
    System.out.println("As Json");
    System.out.println(json);
    System.out.println();
   
    Document result = fromJson(json);
View Full Code Here

Examples of siena.Json

public class JsonSerializerTest extends TestCase {
 
  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);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.