我有一个简单的http-inbound-gateway,它调用服务激活器并将结果返回给HTTP客户机。
service-activator返回一个包含Unicode转义序列的字符串,如下所示:
Fran\u00e7ais这将被传递到http-inbound-gateway,以作为响应有效载荷返回给客户端。
然而,当我调用入站网关的URL时,似乎正在进行一些转换;转义序列被呈现为浏览器无法呈现的二进制格式:
Fran�ais我希望转义序列通过入站http网关并返回给浏览器。
我应该怎么做才能达到这个结果呢?
以下是相关的SI配置:
<http:inbound-gateway
id="inboundGateway"
request-channel="inboundClientRequestChannel"
request-payload-type="java.lang.String"
reply-channel="inboundClientResponseChannel"
reply-timeout="30000"
supported-methods="GET"
message-converters="stringJsonMessageConverter"
path="/test">
<http:request-mapping produces="application/json"/>
</http:inbound-gateway>
<int:service-activator
input-channel="inboundClientRequestChannel"
output-channel="inboundClientResponseChannel"
ref="clientRequestHandler"/>
<bean id="stringJsonMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="writeAcceptCharset" value="false"/>
<property name="supportedMediaTypes">
<list>
<value>application/json</value>
</list>
</property>
</bean>发布于 2015-09-14 04:14:40
这里的问题是,默认情况下,org.springframework.http.converter.StringHttpMessageConverter的实例stringJsonMessageConverter将字符串转换为ISO-8859-1编码。
请参阅Javadoc here。请注意defaultCharset构造函数参数。
初始化stringJsonMessageConverter以使用UTF-8编码解决了这个问题。
https://stackoverflow.com/questions/32553887
复制相似问题