getEntity with GenericType

6k views Asked by At

Trying to get an Entity from a REST service. My code is like this:

I want to send in an object like this: new GenericType<List<MyObject>>() {}

to a methode like this:

public static Object callRestWithUrl(String url, Class<?> responseObject)
            throws MetaServiceException {

        ClientResponse response = RESTConnectionUtils.callMetaService(url);

            result = response.getEntity(responseObject);

        .....

But it gets evaluated to List during runtime and not GenericType and an exception is thrown.

2

There are 2 answers

0
Andreas Blomqvist On

For some reason it started working as is. No idea why. The input to the method needed to be generic.

0
Daniel Lundmark On

How do you invoke your callRestWithUrl method?

It could be that it would work better if your method had the signature:

public static Object callRestWithUrl(String url, GenericType<List<?>> responseObject)

And that you then invoked it as this:

List<...> list = callRestWithUrl(new GenericType<List<MyObject>>() {});

Maybe this web page can help: http://persistentdesigns.com/wp/2009/10/jersey-rest-client/