1

We were discussing with the colleagues as to why the call below returns an array in the ResponseEntity:

    ResponseEntity<WakeupProviderSettingsDTO[]> rep = 
restTemplate.getForEntity(url, WakeupProviderSettingsDTO[].class);

instead of a List<WakeupProviderSettingsDTO> or sth.

Why can't we simply transfer entities as lists?

Is it because There are no Class literals for parameterized types?

Is it a performance thing? is it because of the fixed size of response set?

Orkun
  • 6,998
  • 8
  • 56
  • 103
  • you're specifying the return type as an array in your call: restTemplate.getForEntity(url, WakeupProviderSettingsDTO[].class); so that's what the restTemplate is expecting. I guess this one helps: https://stackoverflow.com/questions/23674046/get-list-of-json-objects-with-spring-resttemplate – groo Jun 20 '18 at 13:19

1 Answers1

1

As you have pointed out in that post.

You can not use .class token with parameterized types

This is one of those rare scenarios where you would use generic type List. So you could do like this

ResponseEntity<List> rep = restTemplate.getForEntity(url, List.class);

But with this you ofcourse lose the advantages that you would get with parameterized types.

If you wish to use List with parameterized types, You can still do it using ParameterizedTypeReference.

To answer your question, this has nothing to do with performance or fixet size response, this is a limitation of java Generics.

pvpkiran
  • 25,582
  • 8
  • 87
  • 134