ARTICLE AD BOX
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.
53.8k14 gold badges159 silver badges206 bronze badges
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();10.2k1 gold badge28 silver badges29 bronze badges
Explore related questions
See similar questions with these tags.

