有没有更好的方法来传递多个 JSON 对象并在 Spring 3 的 @RequestBody 中捕获它?我已经提到了这个,但不希望为该问题中解释的目的定义新的包装类?是 Spring 的限制还是 REST 的限制(根据我的理解,应该不是这样)?迫切需要答案,并且由于我无法在同一问题中发表其他评论(已被删除),因此将其发布在这里。
谢谢,
稻田
对于每个模型使用 @JsonIgnoreProperties(ignoreUnknown = true)
@RequestMapping(value = "/users/testBean", method = RequestMethod.POST, consumes={"application/json","application/xml"}, produces={"application/json","application/xml"})
public @ResponseBody List<User> testBean(@RequestBody Object object) {
System.out.println("testBean called");
System.out.println(object.toString());
ObjectMapper mapper=new ObjectMapper();
User user =mapper.convertValue(object, User.class);
Tree tree =mapper.convertValue(object, Tree.class);
System.out.println("User:"+user.toString());
System.out.println("Tree:"+tree.toString());
return userService.findAll();
}