@RequestMapping(value = "/api/users/create", method = RequestMethod.POST) @ResponseBody public APIPOSTResponse userAdd(@RequestBody User user) { if (user != null) { return userService.addUser(user); } return new APIPOSTResponse(false, "Couldn't add user at this time"); }
Now when i hit this post url with json data it returns me a json.
Although i have just specified here @ResponseBody annotation and nowhere in the controller or the APIPOSTResponse class have i mentioned json etc. This is my custom class.
How did spring automatically converted it to json .
Is it because the request was sent in json ?
HI,
I made the following request :
curl -i -H "Content-Type: application/json" -X POST -d '{"id" : "1", "text" : "r@gmail.com"}' localhost:8080/api/todo/create
So here i am only specifying Content-Type as json...
Spring here auto converts the json to Object and also the object that i return auto converts it to json.
Looks like Content-Type is treated as both ways whereas it appears as if i am only telling spring that the data being sent is json
Please comment.
I made the following request :
curl -i -H "Content-Type: application/json" -X POST -d '{"id" : "1", "text" : "r@gmail.com"}' localhost:8080/api/todo/cr
So here i am only specifying Content-Type as json...
Spring here auto converts the json to Object and also the object that i return auto converts it to json.
Looks like Content-Type is treated as both ways whereas it appears as if i am only telling spring that the data being sent is json
Please comment.