gauti gauti - 7 months ago 28
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.

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);