我找到了一个解决办法。扩展WebMVCConfigureAdapter,并实现ExtendMessageConverter,清除转换器并仅设置所需的转换器。
@Bean
public HttpMessageConverter mappingJackson2HttpMessageConverter(){
MappingJackson2HttpMessageConverter jacksonConverter =
new MappingJackson2HttpMessageConverter(new EventServiceObjectMapper());
return jacksonConverter;
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.clear();
converters.add(new Jaxb2RootElementHttpMessageConverter());
converters.add(mappingJackson2HttpMessageConverter());
}