尝试从 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,并且会引发异常。
最佳答案
如何调用 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/
关于java - 使用 GenericType 获取实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10587378/