加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – 在桌面应用程序中使用RestTemplate消费休息服务时出现

发布时间:2020-12-15 01:25:56 所属栏目:大数据 来源:网络整理
导读:我在桌面应用程序中使用RestTemplate消费休息服务时出现问题,而在Web应用程序中使用时不会出现问题. 这是调试日志 15:30:40.448 [main] DEBUG o.s.web.client.RestTemplate - Reading [java.util.List] as "application/json" using [org.springframework.ht

我在桌面应用程序中使用RestTemplate消费休息服务时出现问题,而在Web应用程序中使用时不会出现问题.

这是调试日志

15:30:40.448 [main] DEBUG o.s.web.client.RestTemplate - Reading [java.util.List] as "application/json" using [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter@98adae2]
15:30:40.452 [main] DEBUG httpclient.wire.content - << "[{"name":"Indonesia","id":1},{"name":"AlaySia","id":2},{"name":"Autraliya","id":3}]"

Exception in thread “main” java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.mgm.domain.Country

这是我使用的代码.

 String url = "http://localhost:8080/mgm/country";
    List

当我将它放在网络应用程序中时,上面的代码不会出错.我使用Spring Rest MVC提供JSON并将其与RestTemplate一起使用.

当Jackson将java.util.LinkedHashMap转换为Country时,我认为存在问题.看起来countries.get(0)实际上有LinkedHashMap类型而不是Country,当我调用Country方法之一时会出现问题,如.getName()

最佳答案
尝试使用数组:

String url = "http://localhost:8080/mgm/country";
List

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读