java - Spring Jackson conditional root wrapping -


i have domain object 1 request need wrap root "row" (for datatables editor).

the problem want root wrapped in response body of 1 controller method.

any suggestions how conditionally enable root wrapping in 1 controller method only? thought enabling in 1 method , writing pointcut around *controller disable on subsequent requests, there's gotta better way...

my spring configuration is:

@override public void configuremessageconverters(list<httpmessageconverter<?>> converters) {     converters.add(jackson2converter()); }  @bean public mappingjackson2httpmessageconverter jackson2converter() {     mappingjackson2httpmessageconverter converter = new mappingjackson2httpmessageconverter();     converter.setobjectmapper(objectmapper());     return converter; }  @bean public objectmapper objectmapper() {     objectmapper objectmapper = new objectmapper();     return objectmapper; } 

this works except case want wrap pojo using @jsonrootname, e.g.: @jsonrootname("row")

i solved problem creating new object mapper in controller , returning json string, e.g.:

objectmapper rootmapper = new objectmapper(); rootmapper.enable(serializationfeature.wrap_root_value); return rootmapper.writevalueasstring(myobject); 

this meant configuring string message converter:

@bean public stringhttpmessageconverter stringmessageconverter() {     stringhttpmessageconverter converter = new stringhttpmessageconverter();     converter.setsupportedmediatypes(arrays.aslist(mediatype.application_json));     return converter; } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -