restTemplate报错 ClassCastException: java.util.LinkedHashMap cannot be cast to

在使用restTemplate调用接口的时候,如果返回值类型是List,
那么在调用此接口时 返回值类型不能用List.class接受 应该改成 T[].class
如下示例:

List forObject = restTemplate.getForObject("http://127.0.0.1:7080/test", List.class);
这样接收会报:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.lang.xu.hao.eurekaserver.controller.UserMy

应改成:

UserMy[] forObject = restTemplate.getForObject("http://127.0.0.1:7080/test", UserMy[].class);

你可能感兴趣的:(spring,spring)