title: Jersey client: How to add a list as query parameter
body: <p>I'm creating a Jersey client for a GET service that has a List as query parameter. According to the <a href="http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e247" rel="noreferrer">documentation</a>, it's possible to have a List as a query parameter (this information is also at <a href="http://jsr311.java.net/nonav/releases/1.1/javax/ws/rs/QueryParam.html" rel="noreferrer">@QueryParam</a> javadoc), check it out:</p>
  <blockquote>
  <p>In general the Java type of the method parameter may:</p>
  <ol>
  <li>Be a primitive type;</li>
  <li>Have a constructor that accepts a single String argument;</li>
  <li>Have a static method named valueOf or fromString that accepts a single String argument (see, for example, Integer.valueOf(String) and java.util.UUID.fromString(String)); or</li>
  <li>Be List, Set or SortedSet, where T satisfies 2 or 3 above. The resulting collection is read-only.</li>
  </ol>
  <p>Sometimes parameters may contain more than one value for the same name. If this is the case then types in 4) may be used to obtain all values.</p>
  </blockquote>
  <p>However, I can't figure out how to add a List query parameter using Jersey client.</p>
  <p>I understand alternative solutions are:</p>
  <ol>
  <li>Use POST instead of GET;</li>
  <li>Transform the List into a JSON string and pass it to the service.</li>
  </ol>
  <p>The first one is not good, because the proper HTTP verb for the service is GET. It is a data retrieval operation.</p>
  <p>The second will be my option if you can't help me out. :)</p>
  <p>I'm also developing the service, so I may change it as needed.</p>
  <p>Thanks!</p>
  <p><strong>Update</strong></p>
  <p>Client code (using json)</p>
  <pre><code>Client client = Client.create();
  
  WebResource webResource = client.resource(uri.toString());
  
  SearchWrapper sw = new SearchWrapper(termo, pagina, ordenacao, hits, SEARCH_VIEW, navegadores);
  
  MultivaluedMap&lt;String, String&gt; params = new MultivaluedMapImpl();
  params.add(&quot;user&quot;, user.toUpperCase()); 
  params.add(&quot;searchWrapperAsJSON&quot;, (new Gson()).toJson(sw));
  
  ClientResponse clientResponse = webResource .path(&quot;/listar&quot;)
                                              .queryParams(params)
                                              .header(HttpHeaders.AUTHORIZATION, AuthenticationHelper.getBasicAuthHeader())
                                              .get(ClientResponse.class);
  
  SearchResultWrapper busca = clientResponse.getEntity(new GenericType&lt;SearchResultWrapper&gt;() {});
  </code></pre>