initial add of EbeanORM server based on v2.8.1

This commit is contained in:
rbygrave
2012-09-14 00:40:39 +12:00
parent 2b74d0f9d9
commit 96ce4c0ddf
1188 changed files with 135034 additions and 0 deletions
@@ -0,0 +1,56 @@
package com.avaje.tests.text.json;
import java.util.List;
import junit.framework.TestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.text.json.JsonContext;
import com.avaje.ebean.text.json.JsonWriteBeanVisitor;
import com.avaje.ebean.text.json.JsonWriteOptions;
import com.avaje.ebean.text.json.JsonWriter;
import com.avaje.tests.model.basic.Customer;
import com.avaje.tests.model.basic.ResetBasicData;
public class TestTextJsonSimple extends TestCase {
public void test() {
ResetBasicData.reset();
List<Customer> list = Ebean.find(Customer.class)
.select("id, name, status, shippingAddress")
.fetch("billingAddress","line1, city")
.fetch("billingAddress.country","*")
.fetch("contacts", "firstName,email")//, new FetchConfig().queryFirst(2))
//.filterMany("contacts").ilike("firstName", "J%").query()
//.where().lt("id", 3)
.order().desc("id")
.findList();
EbeanServer server = Ebean.getServer(null);
JsonContext json = server.createJsonContext();
JsonWriteOptions options = new JsonWriteOptions();
options.setRootPathProperties("name, id");
options.setRootPathVisitor(new JsonWriteBeanVisitor<Customer>() {
public void visit(Customer bean, JsonWriter ctx) {
System.out.println("visiting "+bean);
ctx.appendRawValue("dummy", "34");
}
});
//String s = json.toJsonString(list, true);
String s = json.toJsonString(list, true, options);
System.out.println(s);
List<Customer> mList = json.toList(Customer.class, s);
System.out.println(mList);
}
}