|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.avaje.ebean.text.json.JsonWriteOptions
public class JsonWriteOptions
Provides options for customising the JSON write process.
You can optionally provide a custom JsonValueAdapter to handle specific formatting for Date and DateTime types.
You can optionally register JsonWriteBeanVisitors to customise the processing of the beans as they are processed and add raw JSON elements.
You can explicitly state which properties to include in the JSON output for the root level and each path.
// 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);
JsonContext.toList(Class, String, JsonReadOptions)
Constructor Summary | |
---|---|
JsonWriteOptions()
|
Method Summary | |
---|---|
JsonWriteOptions |
copy()
This creates and returns a copy of these options. |
String |
getCallback()
Return a JSONP callback function. |
PathProperties |
getPathProperties()
Return the properties to include by path. |
JsonValueAdapter |
getValueAdapter()
Return the JsonValueAdapter. |
Map<String,JsonWriteBeanVisitor<?>> |
getVisitorMap()
Return the Map of registered JsonWriteBeanVisitor's by path. |
JsonWriteOptions |
setCallback(String callback)
Set a JSONP callback function. |
void |
setPathProperties(PathProperties pathProperties)
Set the Map of properties to include by path. |
JsonWriteOptions |
setPathProperties(String path,
Set<String> propertiesToInclude)
Set the properties to include in the JSON output for the given path. |
JsonWriteOptions |
setPathProperties(String path,
String propertiesToInclude)
Set the properties to include in the JSON output for the given path. |
JsonWriteOptions |
setPathVisitor(String path,
JsonWriteBeanVisitor<?> visitor)
Register a JsonWriteBeanVisitor for the given path. |
JsonWriteOptions |
setRootPathProperties(Set<String> propertiesToInclude)
Set the properties to include in the JSON output for the root level. |
JsonWriteOptions |
setRootPathProperties(String propertiesToInclude)
Set the properties to include in the JSON output for the root level. |
JsonWriteOptions |
setRootPathVisitor(JsonWriteBeanVisitor<?> visitor)
Register a JsonWriteBeanVisitor for the root level. |
JsonWriteOptions |
setValueAdapter(JsonValueAdapter valueAdapter)
Set a JsonValueAdapter for custom DateTime and Date formatting. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JsonWriteOptions()
Method Detail |
---|
public JsonWriteOptions copy()
Note that it assumes that the JsonWriteBeanVisitor (if defined) are immutable and any JsonWriteBeanVisitor instances are shared between the original and the copy.
public String getCallback()
public JsonWriteOptions setCallback(String callback)
public JsonValueAdapter getValueAdapter()
public JsonWriteOptions setValueAdapter(JsonValueAdapter valueAdapter)
public JsonWriteOptions setRootPathVisitor(JsonWriteBeanVisitor<?> visitor)
public JsonWriteOptions setPathVisitor(String path, JsonWriteBeanVisitor<?> visitor)
public JsonWriteOptions setPathProperties(String path, Set<String> propertiesToInclude)
propertiesToInclude
- The set of properties to outputpublic JsonWriteOptions setPathProperties(String path, String propertiesToInclude)
propertiesToInclude
- Comma delimited list of properties to outputpublic JsonWriteOptions setRootPathProperties(String propertiesToInclude)
propertiesToInclude
- Comma delimited list of properties to outputpublic JsonWriteOptions setRootPathProperties(Set<String> propertiesToInclude)
propertiesToInclude
- The set of properties to outputpublic Map<String,JsonWriteBeanVisitor<?>> getVisitorMap()
public void setPathProperties(PathProperties pathProperties)
public PathProperties getPathProperties()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |