I have this class:
public static class Version {
@Getter private float version;
@Getter private String url;
@Getter private String label;
}
I am attempting to write a generic method for deserializing instances of this, and other classes, from JSON. So far I have:
private <T> List<T> deserializeJSONList(String json) {
try {
TypeReference reference = new TypeReference<List<T>>() {};
return (List<T>) objectMapper.readValue(json, reference);
} catch (JsonProcessingException e) {
throw new RequestException(e);
}
}
Which I call as:
List<Version> versions = deserializeJSONList(response.body());
The problem is that the returned List does not contain Version instances at all, but contains instances of LinkedHashMap, containing key/value pairs representing the fields.
How can I get the generic method to return a List containing objects of the correct type?