Sri Sri - 26 days ago 12
Java Question

Spring REST multiple @RequestBody parameters, possible?

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

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)
Comments