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 should use its default charset [SPR-14821] #19387
To set @responsebody encoding in spring-webmvc, I used to add the following lines in configuration file:
mvc:annotation-driven
mvc:message-converters
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
</mvc:message-converters>
This override the default charset responsebody handler use. And it worked with spring-mvc version 4.2.7 and below.
However, in the latest version of spring-webmvc(4.3.3), this method does not work. In the new version, StringHttpMessageConverter reads content-type from response header, and if content-type string includes charset information, it use this charset and ignores it's default charset.
Hi, to help me to reproduce the issue, could you specify what is the Accept header of the request you send, and what are the Content-Type response headers you receive with Spring MVC 4.2.7 and with Spring MVC 4.3.3 using the configuration you specified in the description? I did a quick try and did not find obvious differences so that would help to identify the use case that produces this behaviour.
Some request headers(same under both versions):
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.8
Response headers under version 4.2.7:
Content-Type:application/json;charset=UTF-8
Response headers under version 4.3.3:
Content-Type:application/json;charset=ISO-8859-1
I tried to make a sample project, and find that there's something wrong in my mvc configuration.
I didn't add <value>application/json;charset=UTF-8</value> in my configuration.
After I add this, the encoding with version 4.3.3 is correct. I don't know why it works with version 4.2.7, but 4.3.3 is ok.
Proved it's not a bug, thank you.
Activity
spring-projects-issues commentedon Oct 19, 2016
Yi commented
The error my lies in org.springframework.http.MediaType.getCharSet() method, since I didn't set charset anywhere, this method should return null.
spring-projects-issues commentedon Oct 19, 2016
Sébastien Deleuze commented
Hi, to help me to reproduce the issue, could you specify what is the
Acceptheader of the request you send, and what are theContent-Typeresponse headers you receive with Spring MVC 4.2.7 and with Spring MVC 4.3.3 using the configuration you specified in the description? I did a quick try and did not find obvious differences so that would help to identify the use case that produces this behaviour.spring-projects-issues commentedon Oct 20, 2016
Yi commented
Some request headers(same under both versions):
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.8
Response headers under version 4.2.7:
Content-Type:application/json;charset=UTF-8
Response headers under version 4.3.3:
Content-Type:application/json;charset=ISO-8859-1
spring-projects-issues commentedon Oct 20, 2016
Sébastien Deleuze commented
I can't reproduce the issue, so could you please provide a sample project that demonstrates the problem?
spring-projects-issues commentedon Oct 21, 2016
Yi commented
I tried to make a sample project, and find that there's something wrong in my mvc configuration.
I didn't add <value>application/json;charset=UTF-8</value> in my configuration.
After I add this, the encoding with version 4.3.3 is correct. I don't know why it works with version 4.2.7, but 4.3.3 is ok.
Proved it's not a bug, thank you.
correct configuration:
mvc:annotation-driven
mvc:message-converters
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
spring-projects-issues commentedon Oct 21, 2016
Yi commented
It's the first time I write issue to spring. Should I close this issue? I haven't seen a close button.
spring-projects-issues commentedon Oct 21, 2016
Sébastien Deleuze commented
I have resolved this issue as invalid, thanks for the update.