Spring REST multiple @RequestBody parameters, possible?

57,889

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)
Share:
57,889
Sri
Author by

Sri

Make stuff. Build things. - https://srirangan.net

Updated on July 08, 2022

Comments

  • Sri
    Sri almost 2 years

    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