Spring REST multiple @RequestBody parameters, possible?

JavaJsonSpringSpring MvcJackson

Java Problem Overview


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

Java Solutions


Solution 1 - Java

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)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSriView Question on Stackoverflow
Solution 1 - JavaSean Patrick FloydView Answer on Stackoverflow