I think it's time to change the default encoding to UTF-8.
There some modules already use UTF-8 as the default encoding.
# Json convert
org.springframework.http.converter.json.AbstractJsonHttpMessageConverter#DEFAULT_CHARSET
# From this MediaType think UTF-8 is already the default encoding
org.springframework.http.MediaType#APPLICATION_JSON_UTF8_VALUE
org.springframework.http.MediaType#APPLICATION_JSON_UTF8
Comment From: pivotal-cla
@chenyhd Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-cla
@chenyhd Thank you for signing the Contributor License Agreement!
Comment From: bclozel
@chenyhd Isn't ISO-8859-1
still the default encoding in the Servlet spec? Wouldn't this change break lots of applications as a result?
Comment From: chenyhd
Hi @bclozel, good point.
I was using version 5.0.4 and faced the same issue as #25328, fixed in 5.2.x
Other things spring web: 1. Use UTF-8 as the default encoding for 'text/plain'.and declarative, you will get 'text/plain;charset=UTF-8'
org.springframework.http.converter.FormHttpMessageConverter#DEFAULT_CHARSET
org.springframework.http.converter.FormHttpMessageConverter#FormHttpMessageConverter
org.springframework.http.converter.FormHttpMessageConverter#applyDefaultCharset
- Use UTF-8 as the default encoding for 'application/json', but not declarative,you will get 'application/json'
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
Should I continue? or close PR?
Comment From: chenyhd
org.springframework.http.MediaType#APPLICATION_JSON_UTF8
marked as @Deprecated
and explain major browser use UTF-8
not servlet change to 'UTF-8' as default encoding
Comment From: chenyhd
I checked out more information, org.springframework.http.MediaType#APPLICATION_JSON_UTF8
marked as @Deprecated
because of RFC 8259 Charset Encoding, But this only for application/json
, I didn't found RFC for text/plain
charset encoding.
Anyway
- application/json
from RFC
- text/plain
from Servlet
The current code is already compatible with both cases.
Comment From: bclozel
Looking at the current situation with form data, plain text and JSON, I think we're in the right place. The Jakarta Servlet spec version 6.0 stills states the following:
If the servlet does not specify a character encoding before the getWriter method of the ServletResponse interface is called or the response is committed, the default ISO-8859-1 is used.
I'm declining this PR as a result. Thanks for looking into it!