Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default content type of response changed in v5.3.11 #27573

Closed
kedar-joshi opened this issue Oct 18, 2021 · 2 comments
Closed

Default content type of response changed in v5.3.11 #27573

kedar-joshi opened this issue Oct 18, 2021 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Milestone

Comments

@kedar-joshi
Copy link

Until Spring Framework v5.3.10, when Accept header is not specified, all API used Content-Type: application/json as default value. This behavior seems to have changed in v5.3.11 where Content-Type: application/xml is being used.

Please refer attached demo.zip.

When following command is used to trigger HTTP request, different responses are returned by API with v5.3.10 and v5.3.11.

curl --request GET --url http://localhost:8080/json

Spring Framework <= v5.3.10

{
  "name": "Neo"
}

Spring Framework v5.3.11

<Json>
  <name>Neo</name>
</Json>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 18, 2021
@bclozel
Copy link
Member

bclozel commented Oct 18, 2021

I've tracked this change down to #27488.

When Spring MVC takes the producible media types and sorts them by specificity and quality, we're getting the following order in the sorted list:

// Spring Framework 5.3.10
0 = {org.springframework.http.MediaType@6104} "application/json"
1 = {org.springframework.http.MediaType@6104} "application/json"
2 = {org.springframework.http.MediaType@6107} "application/xml;charset=UTF-8"
3 = {org.springframework.http.MediaType@6110} "application/xml;charset=UTF-8"
4 = {org.springframework.http.MediaType@6105} "application/*+json"
5 = {org.springframework.http.MediaType@6106} "application/*+json"
6 = {org.springframework.http.MediaType@6108} "text/xml;charset=UTF-8"
7 = {org.springframework.http.MediaType@6109} "application/*+xml;charset=UTF-8"
8 = {org.springframework.http.MediaType@6111} "text/xml;charset=UTF-8"
9 = {org.springframework.http.MediaType@6112} "application/*+xml;charset=UTF-8"

// Spring Framework 5.3.11
0 = {org.springframework.http.MediaType@6101} "application/xml;charset=UTF-8"
1 = {org.springframework.http.MediaType@6102} "text/xml;charset=UTF-8"
2 = {org.springframework.http.MediaType@6104} "application/xml;charset=UTF-8"
3 = {org.springframework.http.MediaType@6105} "text/xml;charset=UTF-8"
4 = {org.springframework.http.MediaType@6098} "application/json"
5 = {org.springframework.http.MediaType@6098} "application/json"
6 = {org.springframework.http.MediaType@6103} "application/*+xml;charset=UTF-8"
7 = {org.springframework.http.MediaType@6106} "application/*+xml;charset=UTF-8"
8 = {org.springframework.http.MediaType@6099} "application/*+json"
9 = {org.springframework.http.MediaType@6100} "application/*+json"

This explains the behavior change you're seeing.

Arguably, not expressing any opinion in the request nor on the controller handler exposed you to an order that's outside of your control and both 5.3.10 or 5.3.11 behaviors are acceptable with the opinions expressed here.

The new ordering looks fine and predictable to me and I don't know how we can roll this back without breaking the fix made in #27488. I'll let @poutsma comment here in case I've missed something, but otherwise I think this issue should be closed.

@poutsma poutsma self-assigned this Oct 18, 2021
@poutsma poutsma added in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 18, 2021
@poutsma poutsma added this to the 5.3.12 milestone Oct 18, 2021
@poutsma
Copy link
Contributor

poutsma commented Oct 19, 2021

@bclozel is correct in saying that the problem at hand is not expressing any media type preference, either through Accept header, suffix, or request parameter (see https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-config-content-negotiation). If you have any control over the client code, I would strongly suggest to improve this. Or, if you simply don't want to return XML, to disable XML support in your configuration.

That said, we do recognize that changing the default content-type in a minor release can be inconvenient, so we have reverted the changes that caused this issue.

poutsma added a commit to poutsma/spring-framework that referenced this issue Oct 20, 2021
The fix made for spring-projectsgh-27488 resulted in a change of the default order
of codecs. This commit reverts these changes, so that the previous
order is restored.

Closes spring-projectsgh-27573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants