我想知道如何提取 List<String>
作为 jersey-2.0
的回应客户。
我已经试过了,
List<String> list = client
.target(url)
.request(MediaType.APPLICATION_JSON)
.get(new GenericType<List<String>>(){});
但是,上面的代码不起作用。它没有返回预期的 List<String>
但是,一个 null
取而代之。
最佳答案
您可以将服务响应作为 Response
类对象,然后使用 readEntity(...)
方法解析此对象。
这是一个快速的代码片段:
List<String> list = client
.target(url)
.request(MediaType.APPLICATION_JSON)
.get(Response.class)
.readEntity(new GenericType<List<String>>() {});
/* Do something with the list object */
关于java - 如何从 jersey2 客户端获取 list<String> 作为响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35313767/