【问题标题】:java.util.List.<init>() in GenericType jersey clientGenericType jersey 客户端中的 java.util.List.<init>()
【发布时间】:2016-10-26 19:06:03
【问题描述】:

我正在使用 jersey restful 应用程序。

在将对象列表从 JSON 转换为对象时出现以下错误。

球衣客户代码

def itemList= clientResponse.getEntity(new GenericType<List<Item>>(){});

堆栈跟踪

Error |
java.lang.NoSuchMethodException: java.util.List.<init>()
Error |
    at java.lang.Class.getConstructor0(Class.java:3074)
Error |
    at java.lang.Class.getDeclaredConstructor(Class.java:2170)
Error |
    at org.springsource.loaded.ri.ReflectiveInterceptor.jlClassGetDeclaredConstructor(ReflectiveInterceptor.java:456)
Error |
    at org.springsource.loaded.ri.ReflectiveInterceptor.jlClassNewInstance(ReflectiveInterceptor.java:983)
Error |
    at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.readFrom(AbstractListElementProvider.java:306)
Error |
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:634)
Error |
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:604)
Error |
    at com.sun.jersey.api.client.ClientResponse$getEntity.call(Unknown Source)

虽然我在 itemList 中得到了正确的值。

谁能告诉我它为什么会出现以及避免它的解决方案是什么?

【问题讨论】:

    标签: java jersey jersey-2.0 jersey-client


    【解决方案1】:

    看起来 Jersey 试图通过反射实例化一个接口(列表),但由于找不到构造函数而失败。

    泽西岛代码应该是

    new GenericType<ArrayList<Item>>()
    

    【讨论】:

      猜你喜欢
      • 2013-02-13
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      • 2018-11-09
      • 2014-11-26
      • 2017-01-17
      相关资源
      最近更新 更多