Spring REST multiple @RequestBody parameters, possible?

Sri picture Sri · Apr 20, 2011 · Viewed 51.9k times · Source

I've implemented a Spring RESTful web service. Using Jackson JSON for Object Mapping. I have a method that accepts two parameters.

public Person createPerson(
    @RequestBody UserContext userContext,
    @RequestBody Person person)

How would the client construct a request where in multiple JSON objects are to be passed in the body?

Is this possible?

-- Sri

Answer

Sean Patrick Floyd picture Sean Patrick Floyd · Apr 20, 2011

I'm pretty sure that won't work. There may be a workaround, but the much easier way would be to introduce a wrapper Object and change your signature:

public class PersonContext{
    private UserContext userContext;
    private Person person;
    // getters and setters
}


public Person createPerson(@RequestBody PersonContext personContext)