Essentially we want to add JSON support to Ebean so that we can use partial objects both to generate JSON and to convert back from JSON.
We want to avoid accidental lazy loading (aware of loaded properties) and generate partially populated beans that can be saved/inserted or updated (in a stateless fashion).
So JSON that is Ebean ORM "aware" and simple to use.
The first cut of this is in HEAD.
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(); String s = json.toJsonString(list, true);
[ {"id":4,"name":"NocCust","status":"ACTIVE", "shippingAddress":null, "billingAddress":null, "contacts":[ ]}, {"id":3,"name":"Fiona","status":"ACTIVE", "shippingAddress":null, "billingAddress":null, "contacts":[ {"id":5,"firstName":"Fiona","email":null}, {"id":6,"firstName":"Tracy","email":null} ]}, {"id":2,"name":"Cust NoAddress","status":"NEW", "shippingAddress":null, "billingAddress":null, "contacts":[ {"id":4,"firstName":"Jack","email":null} ]}, {"id":1,"name":"Rob","status":"NEW", "shippingAddress":{"id":2}, "billingAddress":{"id":1,"line1":"P.O.Box 1234","city":"Auckland", "country":{"code":"NZ","name":"New Zealand"}}, "contacts":[ {"id":1,"firstName":"Jim","email":null}, {"id":2,"firstName":"Fred","email":null}, {"id":3,"firstName":"Bugs","email":null} ]} ]