Package com.avaje.ebean.text.json

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


       
        ElPropertyValue elCmoney = descriptor.getElGetValue("cmoney");
//        ElPropertyValue elCmoneyAmt = descriptor.getElGetValue("cmoney.amount");
//        ElPropertyValue elCmoneyCur = descriptor.getElGetValue("cmoney.currency");
       
        JsonContext jsonContext = server.json();
        String json = jsonContext.toJson(p);
       
        DPerson bean = jsonContext.toBean(DPerson.class, json);
        Assert.assertEquals("first", bean.getFirstName());
        Assert.assertEquals(new Money("12200"), bean.getSalary());
        Assert.assertEquals(new Money("12"), bean.getCmoney().getAmount());
        Assert.assertEquals(NZD, bean.getCmoney().getCurrency());
       
View Full Code Here


   
    Ebean.save(two);
   
    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");
   
   
    UUTwo two2 = jsonContext.toBean(UUTwo.class, jsonString);
   
    Assert.assertEquals(twoX.getId(), two2.getId());
    Assert.assertEquals("twoNameModified", two2.getName());
    Assert.assertEquals("oneNameModified", two2.getMaster().getName());

View Full Code Here

    ResetBasicData.reset();

    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);
    assertTrue(jsonString.contains("{\"status\":\"NEW\",\"name\":\"Rob\"}"));

  }
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(*))");

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

    // Assert.assertTrue(jsonString.indexOf("{\"1\":") > -1);
    // Assert.assertTrue(jsonString.indexOf("{\"id\":1,\"status\":\"NEW\",\"name\":\"Rob\"},")
    // > -1);
View Full Code Here

    SomeEnumBean bean = new SomeEnumBean();
    bean.setId(100l);
    bean.setName("Some name");
    bean.setSomeEnum(SomeEnum.ALPHA);

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

    SomeEnumBean bean2 = json.toBean(SomeEnumBean.class, jsonContent);

    Assert.assertEquals(bean.getSomeEnum(), bean2.getSomeEnum());
    Assert.assertEquals(bean.getName(), bean2.getName());
    Assert.assertEquals(bean.getId(), bean2.getId());
View Full Code Here

    // newDetail.setOrder(order);
    order.addDetail(newDetail);

    EbeanServer server = Ebean.getServer(null);

    JsonContext jsonContext = server.json();
    String jsonString = jsonContext.toJson(order);
    System.out.println(jsonString);

    Order updOrder = jsonContext.toBean(Order.class, jsonString);

    server.update(updOrder);

    MRole r1 = new MRole();
    r1.setRoleName("rolej1");
    Ebean.save(r1);

    MRole r2 = new MRole();
    r2.setRoleName("rolej2");
    Ebean.save(r2);

    MRole r3 = new MRole();
    r3.setRoleName("rolej3");
    Ebean.save(r3);

    MUser u0 = new MUser();
    u0.setUserName("userj1");
    u0.addRole(r1);
    u0.addRole(r2);
    u0.addRole(r3);

    Ebean.save(u0);

    String jsonUser = jsonContext.toJson(u0);

    System.out.println(jsonUser);

    String s = "{\"userid\":" + u0.getUserid()
        + ",\"userName\":\"userj1\", \"roles\":[{\"roleid\":" + r2.getRoleid() + "},{\"roleid\":"
        + r3.getRoleid() + "}]} ";

    MUser updMUser = jsonContext.toBean(MUser.class, s);

    server.update(updMUser);

    // checked transaction log to confirm correct behaviour
  }
View Full Code Here

    ResetBasicData.reset();

    String json0 = "{\"name\":\"InsJson\",\"status\":\"NEW\"}";

    JsonContext jsonContext = Ebean.json();

    // insert
    Customer c0 = jsonContext.toBean(Customer.class, json0);
    Ebean.save(c0);

    // update with optimistic concurrency checking
    String j0 = jsonContext.toJson(c0);
    String j1 = StringHelper.replaceString(j0, "InsJson", "Mod1");
    Customer c1 = jsonContext.toBean(Customer.class, j1);
    Ebean.update(c1);

    // update with no optimistic concurrency checking
    String j2 = "{\"id\":" + c0.getId() + ",\"name\":\"ModIns\",\"status\":\"ACTIVE\"}";
    Customer c2 = jsonContext.toBean(Customer.class, j2);
    Ebean.update(c2);

  }
View Full Code Here

    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

        .fetch("billingAddress", "line1, city")
        .fetch("billingAddress.country", "*")
        .fetch("contacts", "firstName,email")
        .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);

    StringReader reader = new StringReader(s);
    List<Customer> mList2 = json.toList(Customer.class, reader);
    System.out.println("VIA READER: " + mList2);

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

    ResetBasicData.reset();

    List<Customer> list = Ebean.find(Customer.class).select("id, status, shippingAddress").order()
        .desc("id").findList();

    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\""));
    Assert.assertTrue(s.contains("\"name\""));

  }
View Full Code Here

TOP

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

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.