Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list<String> as response from jersey2 client

I want to know how I can extract a List<String> as response from the jersey-2.0 client.

I have already tried this,

List<String> list = client                       .target(url)                       .request(MediaType.APPLICATION_JSON)                       .get(new GenericType<List<String>>(){}); 

But, the above code is not working. It is not returning the expected List<String> but, a null value instead.

like image 911
Saurabh Avatar asked Feb 10 '16 11:02

Saurabh


1 Answers

You can get your service response as Response class object and, then parse this object using readEntity(...) method.

Here is a quick code snippet:

List<String> list = client                       .target(url)                       .request(MediaType.APPLICATION_JSON)                       .get(Response.class)                       .readEntity(new GenericType<List<String>>() {}); /* Do something with the list object */ 
like image 123
user2004685 Avatar answered Sep 17 '22 14:09

user2004685