Reputation: 3209
How can I post a list of items using application/x-www-form-urlencoded
content type ?
For example, I would like to send a List
of :
public class Person {
@NotNull
private String name;
private int age;
// getter/setter...
}
And this is my rest service definition :
@POST
@Path("/persons")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String createPersons(@Valid @FormParam("schedules") List<Person> persons) {
return "OK";
}
But it seems not being accepted by jersey (no injection...). How can I pass non-primitive list of data with JAX-RS ?
Post data looks like that :
persons[0][name]=Test&persons[0][age]=45&persons[1][name]=Test2&persons[1][age]=22
Upvotes: 1
Views: 2702
Reputation: 68
You can use @BeanParam
on your @POST
Listener.
public String createPersons(@Valid @BeanParam List<Person> persons) {
return "OK";
}
But you have to make sure your Person
has @FormParam
annotation for each fields.
Upvotes: 1