How to generify this method? I'm trying to receive a class in my parameter and return a object from that class.
However, Java says that "any.class" int the return is unknown.
Am I doing something wrong with generics? How can I generify this method to receive a ResponseEntity and a Class and then return a Object from that class?
public static <T> T parseToJson(Class<T> any, ResponseEntity responseEntity) {
try {
return new ObjectMapper().readValue(responseEntity.getBody().toString(), any.class);
} catch (IOException e) {
logger.error("Error: " + e.getMessage());
}
}
One more doubt: If I want to return a array of objects, I used to do
return Arrays.asList(new ObjectMapper().readValue(responseEntity.getBody().toString(), ResponseListCameras[].class));
but I'm trying to do
return Arrays.asList(new ObjectMapper().readValue(responseEntity.getBody().toString(), any[]));
and it seems to expect an expression. What can I do?