Hello Rémi,

there are several problems.
1- GET method.
When generating the JSON representation, if the characterSet is not defined, a default one is used (e.g. on my computer, "windows-1252"). Thus, you need to define the right characterSet when defining your JsonRepresentation. Unfortunately, as you noticed, this seems to not work... Fortunately, this bug was fixed yesterday! If you can reach the svn repository, please update your working copy.
If not, please let me know.

2- PUT method.
When you make a PUT request from with AJAX, just because you send data in special character set, you need to specify it with the "charset" parameter of the "Content-type" header.
=> here is your updated AJAX code:
   // GO !
   xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
   xhr.send(jsonData);

And the last but not the least, you test the MediaType of the received entity in the "put" method. Because the MediaType has just been updated (with the charset), the following test does not work:
       "if (entity.getMediaType().equals(MediaType.APPLICATION_JSON)) {"
This is not very intuitive, but you must use another method:
"if (entity.getMediaType().equals(MediaType.APPLICATION_JSON, true)) {" which allows to test the equality between 2 media types by ignoring the parameters...

I hope this wil help you.
Best regards,
Thierry Boileau


Of course, this does not suit you because your string needs UTF-8.
Hi all, I have trouble sending internationalized JSON data. Basically some
characters get lost (e.g the euro € sign).
Here is some sample code :

if (variant.getMediaType().equals(MediaType.APPLICATION_JSON)) {
        JSONObject jo = new JSONObject();
        try {
                jo.put("result", "Iñtërnâtiônàlizætiøn€");
                result = new JsonRepresentation(jo);
                // worse with the following :
                //result.setCharacterSet(CharacterSet.UTF_8);

More generally, what are the guidelines to follow (both at the javascript/client
side and at the restlet/server side) to properly exchange localized JSON data

Sample working source code (including javascript client) at:
http://liihs.univ-tlse1.fr/~bastide/JSONServer.zip
All the best

Reply via email to