java - Return empty JSON from spring controller for void response -


i'm using java 8, tomcat 8, spring-webmvc 4.2.2.release, fasterxml 2.6.3.

i have following method in controller

@requestmapping(method = requestmethod.post) @responsebody public void updatecurrentuserdetails(@requestbody final userdto userdto) {     final userwithid user = securityutil.getcurrentuser();     this.useraccountservice.updateuserdetails(user.getuserid(), user.getusername(), userdto); } 

this method returns void resolves in empty (0 byte) response. clients connecting server expect json reponses even, if empty response.

so configure spring/jackson return {} (2 byte) in case.

i thought returning new object() everywhere in calls return void otherwise imo dirty soution , there must better.

there shouldn't need that. can use 204 response code, made situation describing. don't need responsebody annotation, use:

@requestmapping(method = requestmethod.post) @responsestatus(httpstatus.no_content) public void updatecurrentuserdetails(@requestbody final userdto userdto) {     final userwithid user = securityutil.getcurrentuser();     this.useraccountservice.updateuserdetails(user.getuserid(), user.getusername(), userdto); } 

204 response code:

the 204 (no content) status code indicates server has
fulfilled request , there no additional
content send in response payload body.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -