【发布时间】:2010-12-09 09:26:16
【问题描述】:
我成功地将 spring-mvc 与 json 一起使用,以便在域对象和 json 对象之间进行转换。
现在,我想编写一个控制器,它只接受任何 json、验证它并以紧凑的可序列化形式为服务层提供它。 (json 字符串就足够了,任何紧凑的字节数组表示更好)。我目前的做法是这样的:
@RequestMapping(value="/{key}", method=RequestMethod.GET)
@ResponseBody
public Object getDocument(@PathVariable("username") String username,
@PathVariable("key") String key,
HttpServletRequest request,
HttpServletResponse response) {
LOGGER.info(createAccessLog(request));
Container doc = containerService.get(username, key);
return jacksonmapper.map(doc.getDocument(), Map.class);
}
和
@RequestMapping(value="/{key}", method=RequestMethod.PUT)
public void putDocument(@PathVariable("username") String username,
@PathVariable("key") String key,
@RequestBody Map<String,Object> document,
HttpServletRequest request,
HttpServletResponse response) {
LOGGER.info(createAccessLog(request));
containerService.createOrUpdate(username, key,document);
}
请注意,这种方法不起作用,因为我不想在 put 方法中使用 Map 而 get 方法只返回 {"this":null};。我必须如何配置我的方法?
干杯,
一月
【问题讨论】:
标签: java json spring-mvc