Search code examples
javajerseyjersey-2.0jersey-client

java.util.List.<init>() in GenericType jersey client


i am using jersey restful application.

i am getting below error while converting List of Object from JSON to Object.

jersey client Code

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

Stacktrace

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)

Although i am getting correct values in itemList.

Can anyone tell me why it is coming and what is resolution to avoid it?


Solution

  • Looks like Jersey is trying to instantiate an interface (List) via reflection, and failing because it cannot find the constructor.

    The Jersey code should be

    new GenericType<ArrayList<Item>>()