Problems with Jersey, REST, JSON and UTF-8 [Update]
Published March 22nd, 2008 in JSR 311, Javascript, Jersey, REST, UTF-8, UnicodeUTF-8 is always a problem. Unbelievable. 2008 and we still haven’t fixed this. One of my current projects is a Javascript frontend with a REST backend. The backend stores to MySQL (a famous UTF-8 trouble maker) and creates JSON to REST calls. The problems starts with UTF-8 characters. Somewhere in the callchain - as always - characters don’t get correctly written. MySQL and the JDBC driver should work, the JSP page is UTF-8 (@page and meta-equiv), jQuery - which does the AJAX - and JS do know UTF-8 and Jersey should be UTF-8 too. But with some experiments now I’m quite sure that Jersey (JSR 311 REST framework) is to blame. I’m not sure how to specify UTF-8, this
@ProduceMime("text/plain;charset=UTF-8")
doesn’t help. Funny, every major project with several frameworks along the call chain and several languages (JS, C, Java) makes UTF-8 problems somehow. I’m so fed up with this, it’s 2008.
Update: Jersey uses InputStreams for all encodings, especially StringProvider is relevant to me (se above). Does this work with Unicode?
3 Responses to “Problems with Jersey, REST, JSON and UTF-8 [Update]”
- 1 Pingback on Mar 24th, 2008 at 1:24 pm
- 2 Trackback on Sep 4th, 2008 at 7:23 pm
Hi Stephan,
Yes, i think this is a problem with Jersey, thanks for reporting it.
The EG recently found this issue as well and we have updated the JSR-311 specification, version 0.7 [1], to state:
When writing responses, implementations SHOULD respect application-supplied character set
metadata and SHOULD use UTF-8 if a character set is not specified by the application or if the
application specifies a character set that is unsupported.
and this will be implemented in the 0.7 release of Jersey (scheduled for April 18th).
I should be able to provide you with a specific solution for StringProvider fairly quickly if you are happy working with the latest builds or the trunk.
Paul.
[1] https://jsr311.dev.java.net/