Package com.avaje.ebean.text.json

Examples of com.avaje.ebean.text.json.JsonWriteOptions


public class JsonWriteOptionsTests {

  @Test
  public void test_parse() {
   
    JsonWriteOptions options = JsonWriteOptions.parsePath("id,status,name");
    PathProperties pathProps = options.getPathProperties();
   
    Assert.assertEquals(1, pathProps.getPaths().size());
    Assert.assertTrue(pathProps.get(null).contains("id"));
    Assert.assertTrue(pathProps.get(null).contains("name"));
    Assert.assertTrue(pathProps.get(null).contains("status"));
View Full Code Here


  }

  @Test
  public void test_with_depth() {

    JsonWriteOptions options = JsonWriteOptions.parsePath("id,status,name,customer(id,name,address(street,city)),orders(qty,product(sku,prodName))");
    PathProperties pathProps = options.getPathProperties();

    Assert.assertEquals(5, pathProps.getPaths().size());
    Assert.assertTrue(pathProps.get(null).contains("id"));
    Assert.assertTrue(pathProps.get(null).contains("name"));
    Assert.assertTrue(pathProps.get(null).contains("status"));
View Full Code Here

   
    UUTwo twoX = Ebean.find(UUTwo.class, two.getId());
   
    JsonContext jsonContext = Ebean.json();
   
    JsonWriteOptions writeOptions = JsonWriteOptions.parsePath("(id,name,master(*))");
    String jsonString = jsonContext.toJson(twoX, writeOptions);
   
    System.out.println(jsonString);
    jsonString = jsonString.replace("twoName", "twoNameModified");
    jsonString = jsonString.replace("oneName", "oneNameModified");
View Full Code Here

    List<Customer> customers = Ebean.find(Customer.class).findList();

    JsonContext jsonContext = Ebean.json();

    JsonWriteOptions jsonWriteOptions = JsonWriteOptions.parsePath("(id,status,name)");
    String jsonString = jsonContext.toJson(customers, jsonWriteOptions);
    assertTrue(jsonString.contains("{\"id\":1,\"status\":\"NEW\",\"name\":\"Rob\"}"));

    jsonWriteOptions = JsonWriteOptions.parsePath("status,name");
    jsonString = jsonContext.toJson(customers, jsonWriteOptions);
View Full Code Here

    ResetBasicData.reset();

    Map<String, Customer> map = Ebean.find(Customer.class).findMap("id", String.class);

    JsonContext jsonContext = Ebean.json();
    JsonWriteOptions options = JsonWriteOptions.parsePath("(id,status,name)");

    String jsonString = jsonContext.toJson(map, options);
    System.out.println(jsonString);

    options = JsonWriteOptions.parsePath("(id,status,name,shippingAddress(id,line1,city),billingAddress(*),contacts(*))");
 
View Full Code Here

    List<Customer> customers = Ebean.find(Customer.class)
        .apply(pathProperties)
        .findList();

    JsonWriteOptions options = JsonWriteOptions.parsePath("(id,status,name)");

    String jsonString = Ebean.json().toJson(customers, options);
    System.out.println(jsonString);

View Full Code Here

    ResetBasicData.reset();

    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

    JsonContext json = Ebean.json();

    // test that lazy loading on
    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\""));
View Full Code Here

    JsonContext json = Ebean.json();

    // test that lazy loading on
    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\""));
View Full Code Here

    JsonContext json = Ebean.json();

    // test that lazy loading on
    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\""));
View Full Code Here

TOP

Related Classes of com.avaje.ebean.text.json.JsonWriteOptions

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.