引入sentinel后,json转化异常
生活随笔
收集整理的這篇文章主要介紹了
引入sentinel后,json转化异常
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
添加sentinel依賴后返回的是XML格式的數據而不是JSON格式的數據,是因為sentinel中集成了com.fasterxml.jackson.dataformat的 jackson-dataformat-xml。XML優先級比JSON高,所以會先返回XML。
兩種解決方法:
1,去除sentinel依賴包的com.fasterxml.jackson.dataformat依賴
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId><!--去除jackson-dataformat-xml,否則會返回xml文件,而不是JSON--><exclusions><exclusion><groupId>com.fasterxml.jackson.dataformat</groupId><artifactId>jackson-dataformat-xml</artifactId></exclusion></exclusions> </dependency>2、Crotroller層加返回格式指定
@GetMapping(value = "/typeGoodsList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的引入sentinel后,json转化异常的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Idea创建SpringCloud父
- 下一篇: 全球数字经济白皮书——疫情冲击下的复苏新