Spring MVC & Jackson JSON serialization -


i have question regarding entities serialization json using spring mvc & jackson. have following entities:

@table(name = «a») class {   @column(name = «id»)  integer id;   @column(name = «name»)  string name;   @joincolumn(name = «b_id»)  b b; }  @table(name = «b») class b {  @column(name = «id»)  integer id;   @column(name = «name»)  string name; } 

and have following rest controller returns json response (using jackson integration & spring data repository):

@restcontroller public class acontroller {   @inject  arepository arepository;   @requestmapping(value = «index»)  list<a> getindex() {     return arepository.findall();  } } 

i want exclude response "name" fields (from & b classes). desired json response should like:

[{   id: 1,   b: {     id: 1   } }] 

i know can use @jsonview jackson library, in case (as far know) need put additional @jsonview annotations entity fields.

i want keep domain entities clean ui related stuff , configure response json field list @ ui layer.

for example:

 @json_entity(fieldlist = [‘id’, ‘b.id’]) //specify field list explicitly  //or  @json_entity(view = myjsonview.class) // that's   @requestmapping(value = «index»)  list<a> getindex() {     return arepository.findall();  } 

do have clues on how can done spring?

you can use library denoted in answer, has spring integration: https://stackoverflow.com/a/28388559/5842030


Comments