Skip to content

Revisit converters and codecs default setup in HTTP stacks  #33894

Description

@bclozel

The order of codecs has been the same for a very long time and applications might rely on it.

On the other hand, Spring Boot has been consistently reordering converters and codecs to align with industry trends. For example, reordering XML last in favor of JSON and other converters.

Unfortunately, this creates a disconnect between the order as declared in the application context and what Spring Boot applies in practice. This also causes inconsistencies like spring-projects/spring-boot#43143.

We should consider a change here, as long as there is minimal disruption for Framework and Boot developers.

Activity

  1. added
    in: webIssues in web modules (web, webmvc, webflux, websocket)
    on Nov 15, 2024
  2. added this to the 7.0.x milestone on Nov 15, 2024
  3. self-assigned this
    on Nov 15, 2024
  4. changed the title [-]Consider reordering converters and codecs in HTTP stacks [/-] [+]Consider revisiting converters and codecs default setup in HTTP stacks [/+] on Apr 2, 2025
  5. modified the milestones: 7.0.x, 7.0.0-M6 on May 21, 2025
  6. modified the milestones: 7.0.0-M6, 7.0.x, 7.0.0-M7 on Jun 11, 2025
  7. added a commit that references this issue on Jun 26, 2025
  8. added a commit that references this issue on Jun 26, 2025
    beedf0a
  9. 1 remaining item

  10. added a commit that references this issue on Jun 27, 2025
    7e919d2
  11. changed the title [-]Consider revisiting converters and codecs default setup in HTTP stacks [/-] [+]Revisit converters and codecs default setup in HTTP stacks [/+] on Jul 17, 2025
  12. Ixiodor commented on Sep 11, 2025

    @Ixiodor

    How can I fix this behavior? Right now, RestTemplate uses XML by default, and the same happens with @ControllerAdvice.

  13. bclozel commented on Sep 11, 2025

    @bclozel
    MemberAuthor

    @Ixiodor I don't understand. Can you elaborate? Did you upgrade an application to a 7.0 milestone and see a behavior change? Maybe you can share a minimal sample application that demonstrates one behavior with 6.x and another with 7.0?

  14. Ixiodor commented on Sep 11, 2025

    @Ixiodor

    Hi,
    I'm on:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.5.3</version>
        <relativePath/>
    </parent>
    

    When I check the registered message converters, I see:

    org.springframework.http.converter.ByteArrayHttpMessageConverter
    org.springframework.http.converter.StringHttpMessageConverter
    org.springframework.http.converter.ResourceHttpMessageConverter
    org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter
    org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter
    org.springframework.http.converter.json.MappingJackson2HttpMessageConverter

    Because the XML converter is listed before JSON, the default behavior ends up preferring XML over JSON when the request does not explicitly specify an Accept header.

    This causes some unexpected behavior, for example:

    • Default error pages are returned in XML
    • @ControllerAdvice responses are serialized as XML
    • RestTemplate post uses XML instead of JSON by default

    (Coming from 3.2.2)

  15. bclozel commented on Sep 11, 2025

    @bclozel
    MemberAuthor

    @Ixiodor In this case it's completely unrelated to this issue. You can ask this question on StackOverflow and share here the link, I will have a look.

  16. Ixiodor commented on Sep 11, 2025

    @Ixiodor

    @Ixiodor In this case it's completely unrelated to this issue. You can ask this question on StackOverflow and share here the link, I will have a look.

    https://stackoverflow.com/questions/79762083/spring-changed-converters-order-prefering-xml Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions