问题
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.
回答1:
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/
回答2:
For some reason it started working as is. No idea why. The input to the method needed to be generic.
来源:https://stackoverflow.com/questions/10587378/getentity-with-generictype