我使用的是jersey restful application
我得到下面的错误,而转换对象列表从JSON到对象。
jersey客户端代码
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中得到正确的值。
谁能告诉我为什么它会来,什么是解决办法来避免它?
看起来Jersey试图通过反射实例化一个接口(List),由于找不到构造函数而失败。
Jersey代码应该是
new GenericType<ArrayList<Item>>()