Package siena

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


    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

        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

 
  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

   
    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

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

  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);
View Full Code Here

import siena.Json;

public class JsonTest extends TestCase {
 
  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());
  }
View Full Code Here

    assertEquals(0, json.size());
    assertEquals("[]", json.toString());
  }
 
  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());
  }
View Full Code Here

    assertEquals(0, json.size());
    assertEquals("{}", json.toString());
  }
 
  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());
  }
View Full Code Here

TOP

Related Classes of siena.Json

Copyright © 2018 www.massapicom. 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.