You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
StringHttpMessageConverter doesn't work under UTF-8 [SPR-8486] #13132
After going through the source code of StringHttpMessageConverter, I concludes that although StringHttpMessageConverter has a "DEFAULT_CHARSET" public static member (with default 'ISO-8859-1'), it doesn't offer corresponding setter which leads to the embarrassing that I can't configure StringHttpMessageConverter in applicationContext.xml in a common <property> way.
I suggest that StringHttpMessageConverter should work like FormHttpMessageConverter which contains a private non-static member Charset, and offers corresponding setter for configuration.
Yes. However, it seems that *setSupportedMediaTypes* doesn't change the value of *DEFAULT_CHARSET* after looking into *AbstractHttpMessageConverter*. It just set the *AbstractHttpMessageConverter::supportedMediaTypes*. On the other hand, I've found:
in *StringHttpMessageConverter::writeInternal*, which is called by *AbstractHttpMessageConverter::write*. Then, I'm thinking that my HttpOutputMessage's contentType is not correctly set, otherwise the message converter won't use DEFAULT_CHARSET according to the code above.(I manuallly change it to UTF-8, and it works fine in my project. So I'm sure the DEFAULT_CHARSET is in use other than contentType.getCharSet()). By the way, the message converter is automatically invoked by SpringMVC when I'm returning a string as @ResponseBody in the controller, which means that the content type is mostly like to be automatically set by SpringMVC. So... I'm so sorry that I can't figure out what's wrong indeed...
Then, I'm thinking that my HttpOutputMessage's contentType is not correctly set, otherwise the message converter won't use DEFAULT_CHARSET according to the code above.
The contentType in the HttpOutputMessage is set depending on the Accept header of the request. If there is no Accept header then the default charset is used.
Activity
spring-projects-issues commentedon Jun 27, 2011
Rossen Stoyanchev commented
Have you seen the setSupportedMediaTypes(
List<MediaType>) method available in the base class AbstractHttpMessageConverter?spring-projects-issues commentedon Jun 27, 2011
Steinway Wu commented
Yes. However, it seems that
*setSupportedMediaTypes*doesn't change the value of*DEFAULT_CHARSET*after looking into*AbstractHttpMessageConverter*. It just set the*AbstractHttpMessageConverter::supportedMediaTypes*. On the other hand, I've found:in
*StringHttpMessageConverter::writeInternal*, which is called by*AbstractHttpMessageConverter::write*. Then, I'm thinking that myHttpOutputMessage'scontentTypeis not correctly set, otherwise the message converter won't useDEFAULT_CHARSETaccording to the code above.(I manuallly change it to UTF-8, and it works fine in my project. So I'm sure theDEFAULT_CHARSETis in use other thancontentType.getCharSet()). By the way, the message converter is automatically invoked by SpringMVC when I'm returning a string as@ResponseBodyin the controller, which means that the content type is mostly like to be automatically set by SpringMVC. So... I'm so sorry that I can't figure out what's wrong indeed...spring-projects-issues commentedon Jun 28, 2011
Rossen Stoyanchev commented
The contentType in the HttpOutputMessage is set depending on the Accept header of the request. If there is no Accept header then the default charset is used.
spring-projects-issues commentedon Jun 30, 2011
Steinway Wu commented
Thank you! Firebug told me that my ACCEPT is */*, that's why it didn't work for me.
spring-projects-issues commentedon Apr 22, 2013
blueocci commented
Same issue in our project.
spring-projects-issues commentedon May 7, 2013
Rossen Stoyanchev commented
This has actually be done already as part of #14122.