springboot项目引入这个包以后把原来的json报文改为了xml格式返回
这个是 Spring MVC的消息转换器接口配置的问题,相关源码:
if (!shouldIgnoreXml) {
if (jackson2XmlPresent) {
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.xml();
if (this.applicationContext != null) {
builder.applicationContext(this.applicationContext);
}
messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.build()));
}
else if (jaxb2Present) {
messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
}
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
目前有三种解决方案:
- 干掉spring mvc 中的
MappingJackson2XmlHttpMessageConverter
- 依赖中排除
jackson-dataformat-xml
spring.properties
设置spring.xml.ignore
设置为true
上次更新: 2024/01/30, 15:08:57