In BaseDefaultCodecs (Spring framework 7.0), the registration logic for XML encoders is mutually exclusive:
if Jaxb2XmlEncoder is detected, the framework automatically registers it and skips the registration of JacksonXmlEncoder.
|
if (JAXB_2_PRESENT) { |
|
addCodec(writers, new EncoderHttpMessageWriter<>(this.jaxb2Encoder != null ? |
|
(Jaxb2XmlEncoder) this.jaxb2Encoder : new Jaxb2XmlEncoder())); |
|
} |
|
else if (JACKSON_XML_PRESENT) { |
|
addCodec(writers, new EncoderHttpMessageWriter<>(getJacksonXmlEncoder())); |
Typically, having Jaxb2XmlEncoder available wouldn't be an issue. However, the JAXB API (jakarta.xml.bind:jakarta.xml.bind-api) is often transitively included by widely-used dependencies like spring-data-redis(via spring-oxm).
Because Jaxb2XmlEncoder is prioritized and exclusively registered whenever the JAXB API is present, projects with spring-data-redis(which is almost every Spring Boot project) are forced to use Jaxb2XmlEncoderfor XML serialization.
In BaseDefaultCodecs (Spring framework 7.0), the registration logic for XML encoders is mutually exclusive:
if Jaxb2XmlEncoder is detected, the framework automatically registers it and skips the registration of JacksonXmlEncoder.
spring-framework/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java
Lines 820 to 825 in 9a54f75
Typically, having Jaxb2XmlEncoder available wouldn't be an issue. However, the JAXB API (jakarta.xml.bind:jakarta.xml.bind-api) is often transitively included by widely-used dependencies like spring-data-redis(via spring-oxm).
Because Jaxb2XmlEncoder is prioritized and exclusively registered whenever the JAXB API is present, projects with spring-data-redis(which is almost every Spring Boot project) are forced to use Jaxb2XmlEncoderfor XML serialization.