
com.avaje.ebean.text.json.package-info Maven / Gradle / Ivy
The newest version!
/**
* 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.
*
*
* Example:
*
* // find some customers ...
*
* List<Customer> list = Ebean.find(Customer.class)
* .select("id, name, status, shippingAddress")
* .fetch("billingAddress","line1, city")
* .fetch("billingAddress.country", "*")
* .fetch("contacts", "firstName,email")
* .order().desc("id")
* .findList();
*
* 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);
*
*
*/
package com.avaje.ebean.text.json;
© 2015 - 2025 Weber Informatics LLC | Privacy Policy