I'm trying to call service sending a list as query param using RESTEasy client:
Service:
@POST
@Path("/names")
public void getNames(@QueryParam("name") final List<String> names) {
}
Client:
final MultivaluedMap<String, Object> queryParams = new MultivaluedMapImpl<>();
queryParams.add("name", "name1");
queryParams.add("name", "name2");
final ResteasyClient client = new ResteasyClientBuilder().build();
final ResteasyWebTarget target = client.target(url).queryParams(queryParams);
final Builder builder = target.request();
builder.accept(MediaType.APPLICATION_JSON);
final Response response = builder.post(Entity.form(form));
When I call the /names
endpoint will have 1 element and names.get(0) == [name1, name2]
The problem is solved. The code that I post recently works well.
The wrong code is :
final List<String, String> list = new ArrayList<>();
list.add("name1");
list.add("name2");
final MultivaluedMap<String, Object> queryParams = new MultivaluedMapImpl<>();
queryParams.addAll("name", list);
final ResteasyClient client = new ResteasyClientBuilder().build();
final ResteasyWebTarget target = client.target(url).queryParams(queryParams);;
final Builder builder = target.request();
builder.accept(MediaType.APPLICATION_JSON)
final Response response = builder.post(Entity.form(form));
if I look the code of the class MultivaluedMapImpl i don't find a difference if I use "add" or "addAll" methods!!