0

尝试从 REST 服务获取实体。我的代码是这样的:

我想发送这样的对象:new GenericType<List<MyObject>>() {}

像这样的方法:

public static Object callRestWithUrl(String url, Class<?> responseObject)
            throws MetaServiceException {

        ClientResponse response = RESTConnectionUtils.callMetaService(url);

            result = response.getEntity(responseObject);

        .....

但它在运行时被评估为 List 而不是 GenericType 并引发异常。

4

2 回答 2

4

你如何调用你的 callRestWithUrl 方法?

如果您的方法具有签名,它可能会更好地工作:

public static Object callRestWithUrl(String url, GenericType<List<?>> responseObject)

然后你这样调用它:

List<...> list = callRestWithUrl(new GenericType<List<MyObject>>() {});

也许这个网页可以帮助: http: //persistentdesigns.com/wp/2009/10/jersey-rest-client/

于 2012-05-15T14:54:59.083 回答
0

由于某种原因,它开始按原样工作。不知道为什么。方法的输入需要是通用的。

于 2012-05-15T19:37:57.083 回答