I followed this example, which allows to post a unique Person
object. I want a REST service where I can post a collection of Person
at once, e.g. a
I tried to use @RequestBody List
.
When the request body does not contain any links, it works well, but
if the element carries a link, the server could not deserialize the request body.
Then I tried to use @RequestBody Resources
, but I could not figure out the default name of a list.
Finally, I tried a wrapper which contained List
, and it works.
Here is my solution:
First create a wrapper class for List
:
public class Bulk {
private List> bulk;
// getter and setter
}
Then use @RequestBody Resource
for parameters.
Finally, example json with links for create bulk data in one request:
{
"bulk": [
{
"title": "Spring in Action",
"author": "http://localhost:8080/authors/1"
},
{
"title": "Spring Quick Start",
"author": "http://localhost:8080/authors/2"
}
]
}