I'm trying to write a generic function in Jersey which can be used to fetch a List of objects of the same type through REST. I based it on the informations found in this forum: link
@Override
public <T> List<T> fetchResourceAsList(String url) {
ClientConfig cc = new DefaultClientConfig();
Client c = Client.create(cc);
if (userName!=null && password!=null) {
c.addFilter(new HTTPBasicAuthFilter(userName, password));
}
WebResource resource = c.resource(url);
return resource.get(new GenericType<List<T>>() {});
}
However this is not working. If i try to execute it, i get the following error: SEVERE: A message body reader for Java class java.util.List, and Java type java.util.List<T>, and MIME media type application/xml was not found
.
However if i write this function without templating (replacing T with an actual class name) it just works fine. Of course this way the function loses it's meaning.
Is there a way to fix this?