Setting character encoding within render json

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting character encoding within render json

huseyinbabal
Hi Everyone and @Luke Daley,

When I use json render inside handler like below;

......................
def jsonObject = some_json_object
render json (jsonObject)
.....................


It sets Content-Type as application/json . I use following code to set character encoding;

......................
response.contentType("application/json;charset=utf-8")
response.send(jsonText)
.....................


Is there anyway to set character encoding within render json ?

Thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: Setting character encoding within render json

Luke Daley
Administrator
You can just call response.contentType() before calling render().

The render method will only set it if it hasn’t been set already.

Reply | Threaded
Open this post in threaded view
|

Re: Setting character encoding within render json

huseyinbabal
Hi Luke Daley,

Thanks for your helpful reply. I have already tried that but did not work because we are using v0.9.7 that feature only exists in v0.9.12 :) Anyway, I have tried to upgrade to latest version which is v0.9.12 but there is netty : 4.1.0.Beta4-SNAPSHOT dependency. This dependency gives me 401 error. You can see here also http://repo.spring.io/repo/io/netty/netty-buffer/4.1.0.Beta4-SNAPSHOT/maven-metadata.xml

I wonder if there is any workaround for that?

Thanks in advance
rus
Reply | Threaded
Open this post in threaded view
|

Re: Setting character encoding within render json

rus
You need to add the following maven repository to your build.gradle while we are still on a Netty snapshot

maven { url 'http://clinker.netty.io/nexus/content/repositories/snapshots' }
Reply | Threaded
Open this post in threaded view
|

Re: Setting character encoding within render json

huseyinbabal
Hi rus,

Thanks for reply. I have added that repository, and this time I am getting following error:

Could not resolve all dependencies for configuration ':compile'.
> Artifact 'io.netty:netty-transport-native-epoll:4.1.0.Beta4-SNAPSHOT:netty-transport-native-epoll.jar' not found.

Is there any other dependency?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Setting character encoding within render json

huseyinbabal
In reply to this post by rus
After gradle clean, all the dependency errors gone, and trying to fix unittest related issues. I think GroovyUnitTest removed. Thanks for your help @rus and @Luke Daley
rus
Reply | Threaded
Open this post in threaded view
|

Re: Setting character encoding within render json

rus
Reply | Threaded
Open this post in threaded view
|

Re: Setting character encoding within render json

nicolbiden
In reply to this post by huseyinbabal
More basics about......Character Encoding

Biden