Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i agree with you about alternative solutions which you mentioned above</p> <pre><code>1. Use POST instead of GET; 2. Transform the List into a JSON string and pass it to the service. </code></pre> <p>and its true that you can't add <code>List</code> to <code>MultiValuedMap</code> because of its impl class <code>MultivaluedMapImpl</code> have capability to accept String Key and String Value. which is shown in following figure</p> <p><img src="https://i.stack.imgur.com/kDwdG.png" alt="enter image description here"></p> <p>still you want to do that things than try following code.</p> <p><strong>Controller Class</strong></p> <pre><code>package net.yogesh.test; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import com.google.gson.Gson; @Path("test") public class TestController { @Path("testMethod") @GET @Produces("application/text") public String save( @QueryParam("list") List&lt;String&gt; list) { return new Gson().toJson(list) ; } } </code></pre> <p><strong>Cleint Class</strong></p> <pre><code>package net.yogesh.test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.ws.rs.core.MultivaluedMap; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.core.util.MultivaluedMapImpl; public class Client { public static void main(String[] args) { String op = doGet("http://localhost:8080/JerseyTest/rest/test/testMethod"); System.out.println(op); } private static String doGet(String url){ List&lt;String&gt; list = new ArrayList&lt;String&gt;(); list = Arrays.asList(new String[]{"string1,string2,string3"}); MultivaluedMap&lt;String, String&gt; params = new MultivaluedMapImpl(); String lst = (list.toString()).substring(1, list.toString().length()-1); params.add("list", lst); ClientConfig config = new DefaultClientConfig(); com.sun.jersey.api.client.Client client = com.sun.jersey.api.client.Client.create(config); WebResource resource = client.resource(url); ClientResponse response = resource.queryParams(params).type("application/x-www-form-urlencoded").get(ClientResponse.class); String en = response.getEntity(String.class); return en; } } </code></pre> <p>hope this'll help you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload