/** * JSON formatting and parsing objects (See JsonContext). * <p> * 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. * </p> * * <h3>Example:</h3> * <pre class="code"> * // 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); * * </pre> */ package com.avaje.ebean.text.json;