Package com.avaje.ebean.text.json

JSON formatting and parsing objects (See JsonContext).


Interface Summary
JsonContext Converts objects to and from JSON format.
JsonElement Marker interface for all the Raw JSON types.
JsonReadBeanVisitor<T> Provides for some custom handling of json content as it is read.
JsonValueAdapter Allows you to customise the Date and Timestamp formats.
JsonWriteBeanVisitor<T> Allows for customising the JSON write processing.
JsonWriter The JSON Writer made available to JsonWriteBeanVisitor's so that you can append your own JSON content into the output.

Class Summary
JsonElementArray JSON Array element.
JsonElementBoolean JSON boolean element.
JsonElementNull JSON null element.
JsonElementNumber JSON number element.
JsonElementObject JSON Object element.
JsonElementString JSON string element.
JsonReadOptions Provides the ability to customise the reading of JSON content.
JsonWriteOptions Provides options for customising the JSON write process.

Package com.avaje.ebean.text.json Description

JSON formatting and parsing objects (See JsonContext).

The goal is to provide JSON support taking into account various ORM issues such as partial objects (for fetching and updating), reference beans and bi-directional relationships.


  // find some customers ...
 List<Customer> list = Ebean.find(Customer.class)
     .select("id, name, status, shippingAddress")
     .fetch("billingAddress","line1, city")
     .fetch("", "*")
     .fetch("contacts", "firstName,email")
 JsonContext json = Ebean.createJsonContext();
 JsonWriteOptions writeOptions = new JsonWriteOptions();
 writeOptions.setRootPathVisitor(new JsonWriteBeanVisitor<Customer>() {
     public void visit(Customer bean, JsonWriter ctx) {
         System.out.println("write visit customer: " + bean);
         ctx.appendKeyValue("dummyCust", "34");
         ctx.appendKeyValue("smallCustObject", "{\"a\":34,\"b\":\"asdasdasd\"}");
 writeOptions.setPathProperties("contacts", "firstName,id");
 writeOptions.setPathVisitor("contacts", new JsonWriteBeanVisitor<Contact>() {
     public void visit(Contact bean, JsonWriter ctx) {
         System.out.println("write additional custom json on customer: " + bean);
         ctx.appendKeyValue("dummy", "  3400" + bean.getId() + "");
         ctx.appendKeyValue("smallObject", "{\"contactA\":34,\"contactB\":\"banana\"}");
  // output as a JSON string with pretty formatting
 String s = json.toJsonString(list, true, writeOptions);

Copyright © 2010. All Rights Reserved.