Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to map two objects from same requestBody in spring?

I know that we can map an object using _method(@RequestBody ObjectClass obj).

What i'm trying to achieve is _method(@RequestBody ObjectClass obj, @RequestBody OtherObjectClass obj2) but doesn't work.

Is there some way to map two objects using same request?

Thanks!

like image 696
Pedro Silva Avatar asked Sep 19 '16 11:09

Pedro Silva


1 Answers

A HTTP request is made up of headers and body. For a single request, you have a single request body, you can't have two. You can then parse the request body to extract different variables from it, for example if your request body is a JSON, then you can parse it and convert it into an object.

See this example, further on at section "Passing multiple json objects"

like image 189
evilpenguin Avatar answered Sep 29 '22 10:09

evilpenguin