https://kotlinlang.org logo
#spring
Title
d

dany giguere

09/21/2022, 6:53 PM
Using Spring and Java I’m doing a restTemplate call:
Copy code
restTemplate.exchange(uri, <http://HttpMethod.POST|HttpMethod.POST>, request, Response.class);
the problem is that the response is an array that contains an object. How could I make the Response class to return an array ? I tried doing:
Copy code
restTemplate.exchange(uri, <http://HttpMethod.POST|HttpMethod.POST>, request, ArrayList<Response>.class);
(then I would not need to return the class as an array) But I can only do
ArrayList.class
. It won’t take the
<>
t

Thomas

09/21/2022, 7:12 PM
Hi, try to replace the class with
Copy code
new ParameterizedTypeReference<ArrayList<Response>>() {}
- a typed class is lost when passed as an argument
d

dany giguere

09/21/2022, 7:42 PM
thanks a lot @Thomas It works 🙂
t

Thomas

09/21/2022, 7:42 PM
Cool you're welcome 🙂
n

Neuvine D'Souza

09/22/2022, 5:29 PM
Untitled.kt
Here’s a handy extension function. Usage:
Copy code
<http://restTemplate.post|restTemplate.post><ArrayList<Response>>(uri, request)
29 Views