我想有一个双向JSON到Java序列化
我正在成功使用Java到JSON到JQuery路径......(@ResponseBody)例如
@RequestMapping(value={"/fooBar/{id}"}, method=RequestMethod.GET)
public @ResponseBody FooBar getFooBar(
@PathVariable String id,
HttpServletResponse response , ModelMap model) {
response.setContentType("application/json");
...
}
Run Code Online (Sandbox Code Playgroud)
在我使用的JQuery中
$.getJSON('fooBar/1', function(data) {
//do something
});
Run Code Online (Sandbox Code Playgroud)
这很有效(例如注释工作已经完成,感谢所有的回答者)
但是,如何执行反向路径:使用RequestBody将JSON序列化为Java对象?
无论我尝试什么,我都无法得到这样的东西:
@RequestMapping(value={"/fooBar/save"}, method=RequestMethod.POST)
public String saveFooBar(@RequestBody FooBar fooBar,
HttpServletResponse response , ModelMap model) {
//This method is never called. (it does when I remove the RequestBody...)
}
Run Code Online (Sandbox Code Playgroud)
我已经正确配置了Jackson(它在出路时序列化)并且当然我将MVC设置为注释驱动
我如何使其工作?它有可能吗?或者Spring/JSON/JQuery是单向的(out)?
更新:
我改变了杰克逊的设定
<bean id="jsonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<!-- Bind the return value of the Rest …Run Code Online (Sandbox Code Playgroud)