ursus
01/18/2025, 11:44 PMspring boot I'm trying to use RestTemplate in tests to simply call requests and assert responses.
There are kotlin extensions available for getForObject
@Throws(RestClientException::class)
inline fun <reified T : Any> TestRestTemplate.getForObject(url: String, vararg uriVariables: Any): T? =
getForObject(url, T::class.java, *uriVariables)
However when I use it with a List it breaks
val people = client.getForObject<List<Person>>("/people")
When I hook up debugger the people variable is of type List and then element is LinkedHashMap
If then in debugger I evaluate people.first() I get a class cast exception
Anyone know what's up?ephemient
01/21/2025, 6:15 AMList containing something which isn't a Person. due to generic erasure that can't be checked until the item is retrievedursus
01/21/2025, 9:21 AMephemient
01/21/2025, 9:41 AMClass<*> does not retain
exchange(url, GET, null, object : ParameterizedTypeReference<List<Person>>() {}, *uriVariables)