Before Jackson 3 and Spring Boot 4, we had this code:

import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; @Configuration public class XmlSerialization { @Bean("mappingJackson2XmlHttpMessageConverter") public MappingJackson2XmlHttpMessageConverter mappingJackson2XmlHttpMessageConverter() { JacksonXmlModule customModule = new JacksonXmlModule(); customModule.addSerializer(new CustomListSerializer()); XmlMapper xmlMapper = new XmlMapper(customModule); return new MappingJackson2XmlHttpMessageConverter(xmlMapper); } }

How should one do it after the upgrades?

This is as far as I've got:

import org.springframework.http.converter.xml.JacksonXmlHttpMessageConverter; import tools.jackson.dataformat.xml.XmlModule; import tools.jackson.dataformat.xml.XmlMapper; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class XmlSerialization { @Bean("mappingJackson2XmlHttpMessageConverter") public JacksonXmlHttpMessageConverter mappingJackson2XmlHttpMessageConverter() { XmlModule customModule = new XmlModule(); customModule.addSerializer(new CustomListSerializer()); XmlMapper xmlMapper = XmlMapper.builder().addModule(customModule).build(); return new JacksonXmlHttpMessageConverter(xmlMapper); } }

but there is no addSerializer() in XmlModule.

eis's user avatar

2

There's no addSerializer, but there is addSerializers. That doesn't take a single serializer but an instance of Serializers. The simplest implementation is SimpleSerializers:

SimpleSerializers serializers = new SimpleSerializers(); serializers.addSerializer XmlModule customModule = new XmlModule(); customModule.addSerializers(serializers); XmlMapper xmlMapper = XmlMapper.builder().addModule(customModule).build();

Rob Spoor's user avatar

2 Comments

Ah silly of me missing that. Thank you.

2026-01-28T16:44:10.323Z+00:00

2026-01-28T19:24:20.863Z+00:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.