MappingJackson2HttpMessageConverter bean not being automatically added to MvcConfig's converters list
Opened this issue · 2 comments
In order to be ready for Boot 4.0 we're attempting an upgrade from 3.5.7 to 4.0.0-RC2. We're not ready/able to wholesale migrate to Jackson 3.0 and so we're leveraging the spring-boot-jackson2 dependency for the upgrade.
In our case we don't use Spring's Jackson two dependencies otherwise, but rather direct dependencies on Jackson's 2.20.1 BOM.
In one of our configuration classes we have a method like:
@Bean
public MappingJackson2HttpMessageConverter jsonConverter() {
In which we stand up a Mapper Builder/Mapper that we pass into our own subclass of MappingJackson2HttpMessageConverter and return. We do this to support our own specific JSON transport format.
In Spring Boot 3.5.7 that seems to be the only thing we needed to do for the converter to appear in the converter chain. In Spring Boot 4.0.0-RC1/2 I'm finding that our custom converter is not automatically making it into the chain and I now have to programmatically do so in a WebMvcConfigurer class like so:
@Autowired private MappingJackson2HttpMessageConverter jsonConverter;
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
int index = -1;
for (int i = 0; i < converters.size(); i++) {
HttpMessageConverter<?> converter = converters.get(i);
if (converter instanceof JacksonJsonHttpMessageConverter) {
index = i;
break;
}
}
if (index > 0) {
//Add before the Jackson 3 converter
converters.add(index - 1, jsonConverter);
} else if (index == 0) {
//Unlikely, but...
converters.addFirst(jsonConverter);
} else {
log.error("Could not find expected converter [{}] in converters chain.", JacksonJsonHttpMessageConverter.class.getName());
converters.addLast(jsonConverter);
}
}
Maybe this is the expected path forward, but haven't seen anything in the documentation that I could find that explicitly calls this out. It could also be that how we've been doing this isn't quite the "Spring way" as we've migrated this application into Spring Boot.
Ultimately though I could see this being a stumbling point for other people that need to upgrade Spring Boot to stay in a supported mode, but have significant Jackson 2.0 investment that needs to be migrated. It seems reasonable to expect that MappingJackson2HttpMessageConverter bean classes would still be automatically added to converters if the app is configured to stay with Jackson 2.0.
Some of the docs I looked at:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide
https://spring.io/blog/2025/10/07/introducing-jackson-3-support-in-spring
Thank you!
Thanks for trying out RC2. Unfortunately, we can't diagnose exactly what's happening and why without some more information.
It sounds like you may have both Jackson 2 and Jackson 3 on the classpath. If you also have spring-boot-http-converter and spring-boot-jackson on the classpath, then the auto-configured Jackson 3-based converter may be getting used for application/json requests and responses. If so, setting spring.http.converters.preferred-json-mapper, as described in the reference documentation may help.
If you'd like something more precise than the educated guesswork above, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Thanks for the response @wilkinsona. You're right, it didn't click that Jackson 3 would be being pulled in transitively via some of the other Spring dependencies. I was able to revert out my hack and leverage settings as described above to get our Jackson 2 converter to auto-register.
It might be helpful to link to that other doc in the migration guide in the Jackson 2 section for people who might be in the same boat: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide#jackson-2-compatibility.
Generally speaking do you have any idea of how long or how many releases Spring intends to maintain the bridge support for Jackson 2?
Thanks again for everything!