Anyone know how to get `List` working with `restTe...
# spring
u
Anyone know how to get
List
working with
restTemplate.getForObject<List<X>>
kotlin extension? I'm getting class cast exceptions
d
What's the exact exception? Are you sure you're importing the correct
List
?
u
class cast exception upon accessing the list
d
Copy and paste the exact output, I’m not clairvoyant.
u
Copy code
class java.util.LinkedHashMap cannot be cast to class com.example.demo.Person (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; com.example.demo.Person is in unnamed module of loader 'app')
java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class com.example.demo.Person (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; com.example.demo.Person is in unnamed module of loader 'app')
	at com.example.demo.PersonControllerTests.when POST person is called, bla bla(PersonControllerTests.kt:48)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:767)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	....
Copy code
```val response = client.getForObject<List<Person>>("/people")
val firstPerson = response?.first()
here is a screenshot from debugger - it says the element its a LinkedHashMap, which is obvious nonsense - or rather the otherway around, it ignores the
List<Person>
d
It looks like this the client is a TestRestTemplate. Are you sure you’ve configured the test correctly?
u
yes its test rest template - what do you mean configured tests correctly? all other tests which don't need to parse a List<T> are fine