2013-03-15 2 views
0


여러 JSON 객체를 전달하고 Spring 3의 @RequestBody에서 캡처하는 더 좋은 방법이 있습니까? 나는 this을 언급했지만 그 질문에 설명 된 목적을 위해 새로운 래퍼 클래스를 정의하고 싶지 않으십니까? 그것은 Spring의 제한 또는 REST 제한 (내 이해를 기반으로하며,이 경우가 아니어야합니다)입니까? 절망적으로 대답이 필요하며, 같은 질문에 덧글을 게시 할 수 없어서 (삭제되었습니다) 여기에 게시하십시오.REST URL에서 여러 JSON 객체를 전달하고 Spring @RequestBody를 사용하여 캡처 할 수 있습니까?

감사, 각 모델에 사용 @JsonIgnoreProperties에 대한
패디

답변

0

(ignoreUnknown = TRUE)

@RequestMapping(value = "https://stackoverflow.com/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(); 
} 
관련 문제