I have a very simple question, but I can't seem to find a simple answer:
I got Jackson working to serialize Java beans to JSON in the response using @ResponseBody
But I didn't manage to serialize back JSON to Java beans in the request using @RequestBody
e.g.
// this works fine, Bean is being serialized to JSON
@RequestMapping(...)
public @ResponseBody Bean getSomething(...){
//...
}
// I don't know how to make this work, if if there is a way at all
@RequestMapping(...)
public void setSomething(@RequestBody Bean bean, ...){
//...
}
Update:
See JQuery, Spring MVC @RequestBody and JSON - making it work together some quirks in the configuration (it worked for ResponseBody, but didn't for RequestBody, which doesn't make sense, the configuration is either correct or wrong. could be a bug?)
Yes, it is possible.
Your server side configuration is probably fine if your @ResponseBody is working.
You will need to set the content-type to application/json. The JQuery.ajax() method has a contentType parameter. A great example/summary of AJAX and Spring 3 can be found here. Note that he is using a $.postJSON method, which is most likely this simple plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With