Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
381 views
Welcome To Ask or Share your Answers For Others

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...