gauti gauti - 1 year ago 83
JSON Question

Want to include only some fields of an object that are being mapped to JSON by Genson

My Pojo class contains 50 fields and I need to convert only 10 fields to json.

Genson genson = new Genson.Builder().include("address4", User.class).create();
String json = genson.serialize(user);

"include()" method doesn't seem to be working. Kindly help.

Answer Source
Genson genson = new Genson.Builder()
                 .exclude(Object.class)//this excludes all object types
                 .include("address4", User.class).create();//then add only required fields
String json = genson.serialize(user);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download