You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by Kai Liu <kl...@gmail.com> on 2014/10/27 21:17:22 UTC

Support Chinese Characters in json result for Restful

Dear all,

I use cxf to handle the Restful return as following:

@Path("/")
@Produces("text/json")
public class Manager {
@GET
    public String getRequest(@QueryParam("service") String serviceName)
throws IOException{
.....
return myjsonString;
}
}

The myjsonString is

[{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus","enabled":true,"firstName":"六","lastName":"赵","createDate":"Oct
26, 2014 2:04:56 PM"}]


But When I type the Restful link in the web browser, it shows the
wrong encodings:

[{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus","enabled":true,"firstName":"鍏�","lastName":"璧�","createDate":"Oct
26, 2014 2:04:56 PM"}]


I am wondering how to support Chinese Characters in json result for Restful


Thanks.

Re: Fwd: Support Chinese Characters in json result for Restful

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Thanks for redirecting your query to the users list,
Update @Produces to have "text/json;charset=UTF-8" or set the other 
charset value as needed, that should help...
Let me know if it works please
Cheers, Sergey

On 28/10/14 05:00, Kai Liu wrote:
> Dear all,
>
> I use cxf to handle the Restful return as following:
>
> @Path("/")
> @Produces("text/json")
> public class Manager {
> @GET
>      public String getRequest(@QueryParam("service") String serviceName)
> throws IOException{
> .....
> return myjsonString;
> }
> }
>
> The myjsonString is
>
> [{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus","enabled":true,"firstName":"六","lastName":"赵","createDate":"Oct
> 26, 2014 2:04:56 PM"}]
>
>
> But When I type the Restful link in the web browser, it shows the
> wrong encodings:
>
> [{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus","enabled":true,"firstName":"鍏�","lastName":"璧�","createDate":"Oct
> 26, 2014 2:04:56 PM"}]
>
>
> I am wondering how to support Chinese Characters in json result for Restful
>
>
> Thanks.
>


Fwd: Support Chinese Characters in json result for Restful

Posted by Kai Liu <kl...@gmail.com>.
Dear all,

I use cxf to handle the Restful return as following:

@Path("/")
@Produces("text/json")
public class Manager {
@GET
    public String getRequest(@QueryParam("service") String serviceName)
throws IOException{
.....
return myjsonString;
}
}

The myjsonString is

[{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus","enabled":true,"firstName":"六","lastName":"赵","createDate":"Oct
26, 2014 2:04:56 PM"}]


But When I type the Restful link in the web browser, it shows the
wrong encodings:

[{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus","enabled":true,"firstName":"鍏�","lastName":"璧�","createDate":"Oct
26, 2014 2:04:56 PM"}]


I am wondering how to support Chinese Characters in json result for Restful


Thanks.

Re: Support Chinese Characters in json result for Restful

Posted by Kai Liu <kl...@gmail.com>.
Thanks, Sergey and Aki,

Adding "charset=UTF-8" solved my problem. I sent to issues list without
response then I realized I sent to the wrong list:) Now I know all
questions should go to users list.

Thanks and Best regards,

On Tue, Oct 28, 2014 at 6:40 AM, Aki Yoshida <el...@gmail.com> wrote:

> Hi,
> cxf questions should go to users@cxf and not to dev@cxf.
> So, I'm moving this thread to users@cxf.
>
> Regarding your question, are you sure you are displaying the json
> result using the utf-8 text encoding?
> I suspect you are displaying it (the correct utf-8 encoded json) using
> simplified chinese GB2312.
>
> regards, aki
>
> 2014-10-27 21:17 GMT+01:00 Kai Liu <kl...@gmail.com>:
> > Dear all,
> >
> > I use cxf to handle the Restful return as following:
> >
> > @Path("/")
> > @Produces("text/json")
> > public class Manager {
> > @GET
> >     public String getRequest(@QueryParam("service") String serviceName)
> > throws IOException{
> > .....
> > return myjsonString;
> > }
> > }
> >
> > The myjsonString is
> >
> >
> [{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus
> ","enabled":true,"firstName":"六","lastName":"赵","createDate":"Oct
> > 26, 2014 2:04:56 PM"}]
> >
> >
> > But When I type the Restful link in the web browser, it shows the
> > wrong encodings:
> >
> >
> [{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus
> ","enabled":true,"firstName":"鍏�","lastName":"璧�","createDate":"Oct
> > 26, 2014 2:04:56 PM"}]
> >
> >
> > I am wondering how to support Chinese Characters in json result for
> Restful
> >
> >
> > Thanks.
>

Re: Support Chinese Characters in json result for Restful

Posted by Aki Yoshida <el...@gmail.com>.
Hi,
cxf questions should go to users@cxf and not to dev@cxf.
So, I'm moving this thread to users@cxf.

Regarding your question, are you sure you are displaying the json
result using the utf-8 text encoding?
I suspect you are displaying it (the correct utf-8 encoded json) using
simplified chinese GB2312.

regards, aki

2014-10-27 21:17 GMT+01:00 Kai Liu <kl...@gmail.com>:
> Dear all,
>
> I use cxf to handle the Restful return as following:
>
> @Path("/")
> @Produces("text/json")
> public class Manager {
> @GET
>     public String getRequest(@QueryParam("service") String serviceName)
> throws IOException{
> .....
> return myjsonString;
> }
> }
>
> The myjsonString is
>
> [{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus","enabled":true,"firstName":"六","lastName":"赵","createDate":"Oct
> 26, 2014 2:04:56 PM"}]
>
>
> But When I type the Restful link in the web browser, it shows the
> wrong encodings:
>
> [{"id":{"account":"eucalyptus","user":"zhao6"},"userAccount":"zhao6@eucalyptus","enabled":true,"firstName":"鍏�","lastName":"璧�","createDate":"Oct
> 26, 2014 2:04:56 PM"}]
>
>
> I am wondering how to support Chinese Characters in json result for Restful
>
>
> Thanks.