I am trying to get a list of objects using Spring RestTemplate. I am confused as to why choose ParameterizedTypeReference approach to get list of objects using restTemplate instead of just using Object[].class?
I have checked multiple answers suggesting to use ParameterizedTypeReference. But why can't I just use Object[].class? What limitations do I have?
I have checked this link (https://stackoverflow.com/a/49752261/6001027) where it says, I can use Object[] only for simple cases and have to got for ParameterizedTypeReference while handling complex json structures. Can someone explain me under what cases I cannot use Object[] approach?
ParameterizedTypeReference approach:
ResponseEntity<List<Rating>> responseEntity =
restTemplate.exchange("http://localhost:8084/ratingsdata/user/" + userId,
HttpMethod.GET, null, new ParameterizedTypeReference<List<Rating>>() {
});
List<Rating> ratings = responseEntity.getBody();
Object[] approach:
List<Rating> ratings = Arrays.asList(restTemplate.getForObject("http://localhost:8084/ratingsdata/user/"+userId, Rating[].class));