1


Is there a better way to pass multiple JSON objects and capture it in @RequestBody in Spring 3? I had referred this, but do not wish to define new wrapper classes for the purpose as explained in that question? Is it Spring's limitation or REST limitation (based on my understanding, this should not be the case)? Desperately need answer, and since I could not post additional comments in same question (was deleted), hence posting it here.

Thanks,
Paddy

Community
  • 1
  • 1
Paddy
  • 3,472
  • 5
  • 29
  • 48

1 Answers1

1

for each model use @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();
}
Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
Jay Thakkar
  • 699
  • 1
  • 8
  • 13