JSON 传输数据出现415错误 Content type ‘application/xml;charset=UTF-8’ not supported

2022年11月4日12:57:50
1. 问题:
  • 在微服务项目时,通过 LoadBlance + restTemplate 完成 Consumer 与 Provider 交互时,发生 415 数据格式错误。但是,归根结底,其实就是MVC部分的问题。可能在Cloud使用时暴露出来了。
  • Controller 发送 POST 数据时,虽然已经配置了@RestController注解以及,在返回方法的注解内部设置了返回数据接收类型@PostMapping(value = "xxx", produces = {"application/json;charset=UTF-8"}),页面依旧出现415错误。

2. 解决
  • 目前,本人没有找到什么太好的解决办法。但是,引入下方依赖,可以解决。
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
            <version>2.10.1</version>
        </dependency>
  • 作者:苦荞苦荞丶
  • 原文链接:https://blog.csdn.net/weixin_44311939/article/details/105498355
    更新时间:2022年11月4日12:57:50 ,共 447 字。