Could not extract response: no suitable HttpMessageConverter found for response type [class com.exam
报错信息:Could not extract response: no suitable HttpMessageConverter found for response type [class com.example.vo.WeatherData] and content type [application/octet-stream]
这是在用restTemplate获取uri返回数据,进行数据转换的时候报错的,原来的代码如下:
@Service
public class WeatherServiceImpl implements WeatherService{
@Autowired
RestTemplate restTemplate;
String uri = "http://wthrcdn.etouch.cn/weather_mini?city=深圳";
@Override
public WeatherData getWeather() {
ResponseEntity<WeatherData> weatherData = restTemplate.getForEntity(uri, WeatherData.class);
return weatherData.getBody();
}
}
这里无法直接转换为对象,需要先转为String,再转为自己所需对象,修改后的代码如下
@Service
public class WeatherServiceImpl implements WeatherService{
@Autowired
RestTemplate restTemplate;
String uri = "http://wthrcdn.etouch.cn/weather_mini?city=深圳";
@Override
public WeatherData getWeather() {
ResponseEntity<String> weatherData = restTemplate.getForEntity(uri, String.class);
//使用ObjectMapper进行处理
ObjectMapper mapper = new ObjectMapper();
if(weatherData.getStatusCodeValue() == 200){
String response = weatherData.getBody();
WeatherData weatherData2 = null;
try {
weatherData2 = mapper.readValue(response, WeatherData.class);
} catch (Exception e) {
e.printStackTrace();
}
return weatherData2;
}
return null;
}
}
修改这样,运行后,请求成功
Could not extract response: no suitable HttpMessageConverter found for response type [class com.exam相关推荐
- 小小涉及OpenFeign原理:Could not extract response: no suitable HttpMessageConverter found for response type
一.问题解释(想看总结的去最下面) org.springframework.web.client.UnknownContentTypeException: Could not extract resp ...
- 使用RestTemplate:报错Could not extract response: no suitable HttpMessageConverter found for response typ
项目中需要调用微信接口获取access_token等一系列和微信接口相关的操作,我使用了Spring自带的RestTemplate类来发送Get或Post请求,直接在Spring配置文件中依赖注入 & ...
- RestTemplate请求Could not extract response: no suitable HttpMessageConverter found for response type..
使用 Spring Boot 写项目,需要用到微信接口获取用户信息. 在 Jessey 和 Spring RestTemplate 两个 Rest 客户端中,想到尽量不引入更多的东西,然后就选择了 S ...
- Could not extract response: no suitable HttpMessageConverter found for response type [class java.lan
解决 Could not extract response: no suitable HttpMessageConverter found for response type [class java. ...
- Could not extract response: no suitable HttpMessageConverter found for content type [text/html]
目录 报错信息 源码分析 解决方法 修改 mappingJackson2HttpMessageConverter 配置 继承 mappingJackson2HttpMessageConverter 实 ...
- Could not extract response: no suitable HttpMessageConverter found for response type ***
用RestTemplate.getForObject()获取URL的JSON时,可能会遇到如题所示的报错信息. 我的问题在于:在非MVC的Project中使用RestTemplate. 简单的说,me ...
- openFeig远程调用报错Could not extract response: no suitable HttpMessageConverter found for response type
解决方案:在调用服务和被调用的服务上都加上一个配置类 @Configuration public class jsonConfig {@Beanpublic HttpMessageConverters ...
- Could not extract response: no suitable HttpMessageConverter
版本:spring-cloud-openfeign-core-2.1.1.RELEASE.jar,spring-webmvc-5.1.14.RELEASE.jar,jetty-server-9.4.4 ...
- 【feign】feign.codec.DecodeException: Could not extract response: no suitable HttpMessageConverter
问题描述 在springboot 2的版本中通过feign进行调用,在引入私服jar包并进行调用时,报错: feign.codec.DecodeException: Could not extract ...
最新文章
- ubuntu 中 iptables 和 ufw 的关系
- 微信小程序——真机调试方法(vConsole)
- hql懒加载后判断对象是否存在_hibernate延迟加载(懒加载)详解
- 对python编程做介绍-python002-编程语言介绍
- 10月13日学习内容整理:线程,创建线程(threading模块),守护线程,GIL(全局解释器互斥锁)...
- Cross-Site Scripting(XSS)的类型
- react-native开源组件react-native-wechat学习
- 火狐浏览器常用的几个插件
- netmeeting 人数限止
- 学校机房中计算机软件安装,学校机房软件维护与安装快捷方法.doc
- 趋势客户端修改服务器地址,趋势杀毒软件服务器端更改ip
- 僵尸网络(botnet) DDoS
- 同义词,近义词,反义词收集
- 预测:深度学习未来的6种可能
- VUE之高德地图轨迹绘制与轨迹回放
- 如何给div加遮罩?
- 月薪3000与月薪30000的文案区别
- 安装ubuntu 创建分区_安装Ubuntu后如何创建单独的主分区
- 公司中的一些职位名称及其缩写
- 卢卡斯定理及python实现
热门文章
- 解决Chrome插件安装时出现的“程序包无效”问题
- android qq 邮箱格式,QQ邮箱的正确格式有哪些?文件夹怎么发送呢
- ijkplayer播放器架构从原型到升级
- 天津计算机软件工程学院,天津市软件学院是几本
- 论文笔记:Meta-attention for ViT-backed Continual Learning CVPR 2022
- 树莓派用c语言pwm控制电机,树莓派学习笔记之PWM控制直流电机转速
- mysql的联接算法_联接算法
- reactos操作系统实现(12)
- 华为智能家居app未能连接上远程云服务_华为云主机远程连接不上 华为云服务登录手机版...
- Windows和Linux双系统时间误差8小时解决方案