use of io.s4.client.util.ObjectBuilder in project core by s4.
the class ObjectBuilder method main.
public static void main(String[] argv) throws Exception {
ObjectBuilder b = new ObjectBuilder();
String s = "{a:5, b:100}";
Object out = b.fromJson(s, TEST.class);
System.out.println(out.toString());
TEST t = new TEST(1, 2);
System.out.println(b.toJson(t));
String[] query = { "name", "count", "freq" };
String[] target = { "ACDW", "11" };
io.s4.message.Request.ClientRInfo rinfo = new io.s4.message.Request.ClientRInfo();
rinfo.setRequesterUUID(UUID.randomUUID());
Request req = new io.s4.message.SinglePERequest(Arrays.asList(target), Arrays.asList(query), rinfo);
System.out.println(req.toString());
InstanceCreator<io.s4.message.Request.RInfo> infoCreator = new InstanceCreator<io.s4.message.Request.RInfo>() {
public io.s4.message.Request.RInfo createInstance(Type type) {
return new io.s4.message.Request.ClientRInfo();
}
};
Gson gson = (new GsonBuilder()).registerTypeAdapter(io.s4.message.Request.RInfo.class, infoCreator).registerTypeAdapter(Object.class, new ObjectTypeAdapter()).create();
System.out.println("gson: " + gson.toJson(req));
System.out.println("gson reversed: " + gson.fromJson(gson.toJson(req), SinglePERequest.class));
System.out.println(b.toJson(req));
System.out.println(b.toJson(Arrays.asList(query)));
System.out.println("----------------------------------------------");
ArrayList<SSTest> list = new ArrayList<SSTest>();
SSTest ss1 = new SSTest();
ss1.str = "list-element-1";
SSTest ss2 = new SSTest();
ss2.str = "list-element-2";
list.add(ss1);
list.add(ss2);
Map<String, Object> listmap = new HashMap<String, Object>();
listmap.put("ll", list);
MapTest mt = new MapTest();
mt.map = listmap;
Object listmapobj = listmap;
System.out.println("list: " + gson.toJson(list));
System.out.println("listmap: " + gson.toJson(listmap));
System.out.println("listmapobj: " + gson.toJson(listmapobj));
System.out.println("mapobject: " + gson.toJson(mt));
}
Aggregations