java - How to ignore json property in encapsulated design -
class a{ private b b; //other properties //getter setter } // unable add jsonignore in class due dependency in other module class b { int id; string name; string defname; }
i want ignore defname
in class a
json building codehaus.jackson
api.
i need {a:{id:value,name:value}}
.
you can use mixin purpose.
first create abstract class jsonignore annotation:
abstract class mixin{ @jsonignore abstract string getdefname(); }
then use below. (be sure getter name of defname field getdefname() in b class or change in mixin class yours.)
objectmapper objectmapper = new objectmapper(); objectmapper.addmixin( b.class, mixin.class ); objectmapper.writevalue( system.out, new a() );
this prints:
{"b":{"id":1,"name":"sercan"}}
Comments
Post a Comment