• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rest jersey client passing json string to GET method for filter output

aditya sam
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to pass string {"filters":{"keyword":"abc"}} in this format as filter or search parameter to GET method for REST api url.

I want to convert curl parameters to get method to jersey rest call, the inline curl when executed from linux box works for me
curl -i -H "accept: application/json" -H "Content-type: application/json" -X GET -d '{ "filters": { "keyword":"xyz" } }' ../v1/users?token=[api_token] .

I tried using the inline code but with less luck
Client client = Client.create();
WebResource webResource = client.resource(url);
ClientResponse response2 = null;
MultivaluedMap<String, String> queryParams;
List<String> list = new ArrayList<String>();
list = Arrays.asList(new String[]{"{keyword:xyz}"});
String lst = (list.toString()).substring(1, list.toString().length()-1);
queryParams.add("filters", lst);
response2 = webResource.queryParams(queryParams).header("Content-Type", "application/json;charset=UTF-8").get(ClientResponse.class);
System.out.println("Response Code = "+response2.getStatus());
outputFilter = response2.getEntity(String.class);

Is there another way from where i can pass string as input paramters to GET method and retrieve the associated result Please suggest if there is any technique from where i can pass the above mentioned string to GET method and retrieve data as per filter applied
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic