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 https://github.com/spring-projects/spring-boot/issues/43143.

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

Comment From: bclozel

Reopening as the multipart converter is ordered at the end for server converters, whereas it should be ordered after the base converters (string, byte array, resources) but before the core converters (json, xml, etc).

Comment From: Ixiodor

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

Comment From: bclozel

@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?

Comment From: 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)

Comment From: bclozel

@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.

Comment From: 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