jackson - how to manage multiple http response status code while using spring message converters -


in our api using spring jackson http message converter automatically convert java object json. enjoying feature,but feel i've lost control on response http status code.if want return response different status codes ,i have choice of using @responsestatus(httpstatus),but cannot specify status dynamically,as annotation expecting enum const expression. other choice http server response.set status(),but don't that.spring's responseentity(jsonstring,statuscode) great thing solve if want use jackson httpmessageconverter way configure response status code dynamically.

you can return responseentity<myobject> controller method , still use configured message converters, example:

@restcontroller @requestmapping("/foo") public class foocontroller {     @requestmapping     public responseentity<myobject> foo() {         myobject myobject = new myobject();         // can dynamically set status based on needs         httpstatus status = httpstatus.ok;         return new responseentity<>(myobject, status);     } } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -