4

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]

3
  • @Cássio Mazzochi Molin: The URI including the query parameters is usually used to identify a resource whereas the body of the request contains a representation of the resource. So in some cases it might make sense to e.g. POST a present to loyal customers: /customers?minOrders=10. Commented Oct 21, 2015 at 2:19
  • @user3784148: Which version of RESTeasy are you using? Can't reproduce it with 3.0.6.Final. Or maybe misunderstood your problem. Commented Oct 21, 2015 at 2:20
  • @lefloh I've tried to edit and accidentally removed my comment. You are completely right about the use of query parameters in POST requests. Thanks for providing an example. Commented Oct 21, 2015 at 7:31

1 Answer 1

2

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!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.