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

StringHttpMessageConverter should assume charset UTF-8 for application/json [SPR-17568] #22100

Closed
spring-issuemaster opened this Issue Dec 5, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Dec 5, 2018

Thomas Meyer opened SPR-17568 and commented

When using "@RequestBody String jsonString" for an @Controller's @RequestMapping and the body is send as application/json with UTF-8 encoding, Spring uses StringHttpMessageConverter to convert the message, as the content-type will be application/json without any explicit encoding, so the StringHttpMessageConverter will fall back to the default encoding ISO-8859-1 which may is in accordance with the HTTP spec but not with RFC7159, which says: "The default encoding is UTF-8" (chapter 8.1)

 

So the suggestion would be to add an exception in the StringHttpMessageConverter to use UTF-8 charset for application/json.

 

 


Affects: 5.1.3

Referenced from: commits 05d6162

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Dec 5, 2018

Thomas Meyer commented

When using Jersey as client it's especially problematic as Jersey's StringMessageProvider (https://github.com/jersey/jersey/blob/master/core-common/src/main/java/org/glassfish/jersey/message/internal/StringMessageProvider.java ) uses default encoding UTF-8 for content-type application/json.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Dec 5, 2018

Rossen Stoyanchev commented

This is also supported by the current HTTP 1.1 spec RFC 7231:

The default charset of ISO-8859-1 for text media types has been
removed; the default is now whatever the media type definition says.

We can update StringHttpMessageConverter to check for application/*+json and use UTF-8, which is what AbstractJackson2HttpMessageConverter does by default.

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