title: Wrong UTF-8 string parsing in GWT JSON
body: <p>my stack is overflow :):):):) I can't find the solution...</p>
  
  <p>I'm developing a server-client application.
  My GWT client running in browser. Communicate with my C++ server by:
  GWT-JSON -> lighttpd -> libfcgi -> cgicc -> libjson -> C++ application</p>
  
  <p>My problem:
  The server response with a JSON string to client's request. This response contains UTF-8 strings. Accent characters encoded correctly with "\uXXXX" in response. For example: "Á" encoded: "\u00C3\u0081".
  The client extract the string from JSON string. But the extracted string contains bad encoded characters. :(:(:(:(</p>
  
  <p>Lucky, I can narrow the problem to JSON-GWT. Here is a code to demonstrate the problem, running in client side only in GWT:</p>
  
  <pre><code>String response="{ \"test\" : \"\\u00C3\\u0081\\u00C3\\u0089\\u00C5\\u00B0\" }"; //"ÁÉÜ" in UTF-8
  JSONObject json=JSONParser.parseStrict(response).isObject();
  String s1=json.get("test").isString().stringValue();
  Window.alert(s1);
  byte[] b1=s1.getBytes();
  </code></pre>
  
  <p>The results:</p>
  
  <pre><code>Alert is: "ÃÃ‰Å°" instead of "ÁÉÜ"
  s1="ÃÃ‰Å°" instead of "ÁÉÜ"
  b1=[ 0xc3, 0x83, 0xc2, 0x81, 0xc3, 0x83, 0xc2, 0x89, 0xc3, 0x85, 0xc4, 0xb0 ] (incorrect)
  </code></pre>
  
  <p>Here is an another test:</p>
  
  <pre><code>String s2="ÁÉŰ";
  Window.alert(s2);
  byte[] b2=s2.getBytes();
  </code></pre>
  
  <p>The results:</p>
  
  <pre><code>Alert: "ÁÉÜ" (correct)
  s2="ÁÉÜ" (correct)
  b2=[ 0xc3, 0x81, 0xc3, 0x89, 0xc5, 0xb0 ] (correct, same as in "response" string above)
  </code></pre>
  
  <p>I think, the JSONParser.parseStrict or JSONObject.get().isString().stringValue() can't handle correctly the UTF-8 characters...</p>
  
  <p>Any idea? :(:(:(:(</p>
  
  <p>Additional information:
  The request and response Content-Type is "application/json; charset=UTF-8". Source code files and the development environment use UTF-8. The HTML page in browser encoding also UTF-8.</p>
  
  <p>I have problem only with the response only. The request character coding/encoding is correct.</p>
  
  <p>Thank you for any help,
  Tibor</p>
  
  <p><strong>Update1:</strong></p>
  
  <pre><code>String s1b=new String(s1.getBytes("ISO-8859-1"));
  </code></pre>
  
  <p>Returns:
   s1b="ÁÉÜ" (correct)</p>
  
  <p>It's ugly, and strange. Why I need to convert UTF-8 string to ISO-8859-1 to get an UTF-8 string again? I don't understand... :(:(:( </p>
  
  <p><strong>Update2:</strong></p>
  
  <p>If I disable "\u00xx" escaping in JSON writer in server side, all works as expected. But this is not a good idea according to RFC4627 :((((. In this mode, the JSON string transports the non-printable characters (0xc3, 0x81, 0xc3, 0x89, 0xc5, 0xb0) ("ÁÉÚ" in UTF-8) without any encoding.... :(:(:(
  GWT JSON parser expands the UTF-8 character correctly, and the alert displays correct characters.
  I think continuously, the wrong decoding is near to GWT JSON decoding... </p>