Package com.avaje.ebean.text.json

Examples of com.avaje.ebean.text.json.JsonContext.toJson()


    List<Customer> list = Ebean.find(Customer.class).select("name").findList();

    JsonWriteOptions opt = JsonWriteOptions.parsePath("name, status");

    JsonContext jsonContext = Ebean.json();
    String jsonString = jsonContext.toJson(list, opt);

    System.out.println(jsonString);

  }
}
View Full Code Here


        .order().desc("id").findList();

    JsonContext json = Ebean.json();


    String s = json.toJson(list);
    System.out.println(s);

    List<Customer> mList = json.toList(Customer.class, s);
    System.out.println("VIA STRING: " + mList);
View Full Code Here

    PathProperties pp = PathProperties.parse("(id,name,contacts(firstName))");
    JsonWriteOptions o = new JsonWriteOptions();
    o.setPathProperties(pp);

    System.out.println("Expect lazy loading of Customer beans and customer contacts");
    String s = json.toJson(list, o);
    System.out.println(s);
    Assert.assertTrue(s.contains("\"contacts\""));
    Assert.assertTrue(s.contains("\"name\""));

  }
View Full Code Here

    PathProperties pp = PathProperties.parse("(id,name,contacts(firstName))");
    JsonWriteOptions o = new JsonWriteOptions();
    o.setPathProperties(pp);

    System.out.println("expecting lazy load of Customer beans to fetch customer name");
    String s = json.toJson(list, o);
    System.out.println(s);
    Assert.assertTrue(s.contains("\"contacts\""));
    Assert.assertTrue(s.contains("\"name\""));

  }
View Full Code Here

    PathProperties pp = PathProperties.parse("(id,name,contacts(firstName))");
    JsonWriteOptions o = new JsonWriteOptions();
    o.setPathProperties(pp);

    System.out.println("expecting lazy load of Customer contacts ");
    String s = json.toJson(list, o);
    System.out.println(s);
    Assert.assertTrue(s.contains("\"contacts\""));
    Assert.assertTrue(s.contains("\"name\""));

  }
View Full Code Here

    cat.setName("Gemma");

    Ebean.save(cat);

    JsonContext json = Ebean.json();
    String jsonContent = json.toJson(cat);

    Cat cat2 = json.toBean(Cat.class, jsonContent);

    Assert.assertEquals(cat.getId(), cat2.getId());
    Assert.assertEquals(cat.getName(), cat2.getName());
View Full Code Here

    Ebean.save(dog);

    List<Animal> animals = Ebean.find(Animal.class).findList();

    String listJson = json.toJson(animals);

    List<Animal> animals2 = json.toList(Animal.class, listJson);
    Assert.assertEquals(animals.size(), animals2.size());

    String noDiscList = "[{\"id\":1,\"name\":\"Gemma\",\"version\":1},{\"name\":\"PussCat\",\"version\":1},{\"species\":\"CAT\",\"name\":\"PussCat\",\"version\":1}]";
View Full Code Here

    EbeanServer server = Ebean.getServer(null);

    JsonContext json = server.json();

    String jsonOutput = json.toJson(list);
    System.out.println(jsonOutput);

    List<Customer> mList = json.toList(Customer.class, jsonOutput);

    Assert.assertEquals(list.size(), mList.size());
View Full Code Here

    JsonContext json = server.json();

    if (list.size() > 1) {
      Customer customer = list.get(0);

      String s = json.toJson(customer);
      System.out.println(s);
      int statusPos = s.indexOf("status");
      Assert.assertEquals(-1, statusPos);
    }
View Full Code Here

    List<Vehicle> list = Ebean.find(Vehicle.class).setAutofetch(false).findList();

    Assert.assertEquals(2, list.size());

    JsonContext jsonContext = Ebean.json();
    String jsonString = jsonContext.toJson(list);
    System.out.println(jsonString);

    List<Vehicle> rebuiltList = jsonContext.toList(Vehicle.class, jsonString);

    Assert.assertEquals(2, rebuiltList.size());
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.