Skip to content

JacksonXmlEncoder.canEncode incorrectly returns true for String body with application/xml #36775

Closed

Description

@yikuo123

When using Spring Boot 4's WebClient to send an XML request with a String body and Content-Type: application/xml, the request fails with:

Stream decoding is currently not supported

Minimal Reproducer:

webClient
.post()
.uri(url)
.contentType(MediaType.APPLICATION_XML)
.bodyValue("<xml><a>test</a></xml>")
.retrieve();

Root Cause Analysis

The failure is caused by JacksonXmlEncoder#canEncode, which returns true for MediaType.APPLICATION_XML + String.

However, Jackson’s XML encoder does not​ actually support encoding raw String values.

This behavior differs from JacksonJsonEncoder, which explicitly prevents this case via:

@Override
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
    return super.canEncode(elementType, mimeType) && !String.class.isAssignableFrom(elementType.toClass());
}

JacksonXmlEncoder does not​ override canEncode, so it incorrectly signals support for String bodies.

Expected Behavior

JacksonXmlEncoder.canEncode should return false for String types, similar to JacksonJsonEncoder. And falls back to a non-streaming encoder for String bodies with application/xml.

Activity

  1. added
    status: waiting-for-triage
    on May 11, 2026
  2. rstoyanchev commented on May 21, 2026

    @rstoyanchev
    Contributor

    This looks like a regression after #35872 and c10266e, which moved String checks to the JSON codec level from AbastractJacksonEncoder and AbstractJacksonDecoder as those do not make sense for binary formats. The same change should be applied to the XML codec level.

  3. added
    in: web
    type: regression
    and removed
    status: waiting-for-triage
    on May 21, 2026
  4. added this to the 7.0.8 milestone on May 21, 2026
  5. self-assigned this
    on May 21, 2026
  6. sdeleuze commented on Jun 1, 2026

    @sdeleuze
    Contributor

    +1 to what @rstoyanchev said.

  7. removed this from the 7.0.8 milestone on Jun 2, 2026
  8. added
    status: superseded
    on Jun 2, 2026
  9. removed
    status: superseded
    on Jun 5, 2026
  10. added this to the 7.0.8 milestone on Jun 5, 2026
  11. added a commit that references this issue on Jun 5, 2026
    95bd3f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: regression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions