I have a spring bean that takes predefined hashmap values from application context.
<util:map map-class="java.util.HashMap" id="keyValues">
<entry key="key1" value= "value1"/>
<entry key="key2" value= "value2"/>
<entry key="key3" value= "value3"/>
<entry key="key4" value= "value4"/>
</util:map>
Until now, this hashmap never had non-English characters. But now a new key value having Chinese text is added (value4). This text breaks in the application and shows "?????".
I have also tried setting the tomcat encoding, but that did not help. Also that may not be an appropriate solution as it may break existing values.
In the java class where these values are consumed, if I use URLEncode.encode(value4);
, it just works fine.
What my question here is, is there any way to make spring do URLEncode for me? This is to avoid making a java change and instead just do a applicationContext.xml change.
Thanks in advance.
I would try sth like this:
assuming that method is static (I guess you use own class for encoding) and then pass reference:
but if you need to encode more values then maybe it would be easier to write own factory class which produces hashmap with encoded values