如何获取列表< String>作为来自jersey2客户的回复 [英] How to get list<String> as response from jersey2 client

查看:89
本文介绍了如何获取列表< String>作为来自jersey2客户的回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这个,

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

但我没有得到列表而是获得空值

but I am not getting the list instead I am getting null value

推荐答案

在响应对象中获取响应,然后使用 readEntity()方法解析响应对象。

Take your Response in the Response Object and then parse the Response Object using readEntity() method.

以下是一段快速代码段:

Here is a quick code snippet:

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

这篇关于如何获取列表&lt; String&gt;作为来自jersey2客户的回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆