Skip to content

Jaxb2XmlEncoder exclusivity prevents JacksonXmlEncoder usage and hinders POJO serialization #36776

@yikuo123

Description

@yikuo123

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions