UTF-8 (Chinese) in servoy REST Webservice

Hi,

I’m trying to get chinese working in the REST service and I hope someone can point me in the right direction.
Inside of Servoy it is all working correctly, but when it exits servoy and we look in a sniffer and at the client, the texts is wrong.

What I have so far. (when I check _result, it is still 羅莎大)

var bytes = _result.getBytes("UTF-8");
return bytes;

Before I had only .getBytes() → this resulted in ??? instead of 羅莎大.
When we added .getBytes(“UTF-8”) → it became 羅莎大. Which is the ANSI encoding.

Other actions we have tried: changed the server.xml of tomcat/apache and added URIEncoding=“UTF-8” to the connector, but that also doesn’t work. Still 羅莎大.
Also I made a test c# client, which ads UTF8 to the request, but it still returns 羅莎大.

HttpResponseMessage response = await client.PostAsync(targetUrl, new StringContent(requestData, Encoding.UTF8, "application/json"));
            HttpContent content = response.Content;                       
            var byteArray = await content.ReadAsByteArrayAsync();
            var result = Encoding.UTF8.GetString(byteArray, 0, byteArray.Length);

Is there anyone who knows in which direction we can further look?
It feels like I’m missing something in servoy or in apache/tomcat.

Hi Jos,

What is the reason to return bytes instead of the string?
Also what content-type does the REST api return?

Hi,

To be honest, I don’t know why it returns bytes. The project was developed by another developer and transferred to me.
But the difference I notice when I remove the .getBytes() is that the json that is returned isn’t valid.

For example without the .getBytes it is:

/"property/"=10

Instead of

"property"=10

But the content type of the response is application/json;charset=UTF-8.
So I’m starting to think, I’m doing something strange somewhere. As it all seems to be correct. :)

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: xxxxx
Vary: Origin
Access-Control-Max-Age: 1728000
Cache-Control: max-age=0, must-revalidate, proxy-revalidate
Expires: 0
Content-Type: application/json;charset=UTF-8
Content-Length: 533
Date: Sun, 30 Dec 2018 18:42:00 GMT

Still the:
"productgroup":"羅莎大"

Thanks Robert!
It did gave me the idea, to build up a object in code to return immediatly, instead of building the json object in a string.

That has solved the problem.

This project was still on servoy 6.x though, so it was a bit of a search, because JSON.stringify came available later. But luckily I found the answer on this forum to, to use json2 stringify.