utf8 encoding issue

1,265 views
Skip to first unread message

Sven Haiges

unread,
Dec 19, 2012, 6:01:45 AM12/19/12
to gae...@googlegroups.com
Hi all, 

I noticed today that some json that I generate usign the JsonBuilder is wrongly encoded. The problem is, though, that the issue does not exist locally. I am on a mac locally, files are saved in UTF-8 in TextWrangler for this Gaelyk project. I also left the utf-8 defaults in the appengine.xml file.

So, here my controller:

import groovy.json.*
import java.net.URLEncoder

//response
response.contentType='application/json'
response.setHeader("Access-Control-Allow-Origin", "*")

def builder = new JsonBuilder()
builder {
city 'München'
}
builder.writeTo(out)

on app engine (*.appspot.com) I get this:
{"city":"M\u221A\u00BAnchen"}

localhost:8080 I get this (which is correct)
{"city":"M\u00FCnchen"}

What is the Problem? Is this a known issue?

Cheers
Sven

jim

unread,
Dec 20, 2012, 9:13:58 AM12/20/12
to gae...@googlegroups.com
not sure there , but my first guess would be that the encoding of your source files and/or appengine.xml declarations might not be 'seen' by the http request/response.  i would have tried something like :
request.setCharacterEncoding("UTF-8")

on the request call, also we may need to set the same on the response, but that's not something i'm familiar with - sorry.

Sven Haiges

unread,
Dec 21, 2012, 6:23:31 AM12/21/12
to gae...@googlegroups.com
thx for the comments. I now noticed another issue, also with encoding.

I have to send a json file to the server and have it processed. It will end up as account entities in the database. The problem here, again, is that the special charactes, gemran umlauts, etc. are all broken. 

When I look at the json file on my system, I can see that the Groovy JsonBuilder correctly transformed a ü into \uXXXX for exampel. So I think the input file is really valid. 

I then use the RestClient java app to send the file to the server:
POST /accounts
Content-Type application/json; charset=utf-8

body: the file in text form

on the server, I try to read it:

def slurper = new JsonSlurper().parse(new InputStreamReader(request.inputStream))
... the rest is pretty basic processing, and saving the entities.

Again, the characters for ü for example are broken. I am not quite undestanding this... 

Anyone? Any help really appreciated.

Guillaume Laforge

unread,
Dec 21, 2012, 6:42:48 AM12/21/12
to gae...@googlegroups.com
You should try to customize the input stream reader that you're using to specify the correct encoding to be used, if for some reason it's not recognized automatically.


--
You've received this message because you've subscribed to the Gaelyk Google Group.
To send an email to the group, please write to: gae...@googlegroups.com
To unsuscribe from this group: gaelyk+un...@googlegroups.com
To show more options: http://groups.google.fr/group/gaelyk?hl=en



--
Guillaume Laforge
Groovy Project Manager
SpringSource, a division of VMware

Reply all
Reply to author
Forward
0 new messages