简体   繁体   中英

Apache cxf Jax Rs encoding issue

I am using jaxrs with Apache cxf . Below is the xml config

<jaxrs:server id="accountrs" address="/rservice">
        <jaxrs:serviceBeans>
            <ref bean="accountService"/>
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <ref bean='jsonProvider' />
        </jaxrs:providers>
    </jaxrs:server>

For some of my post methods i see that that the double byte charectors are getting distorted and appearing as garbled charectors and getting stored in the database .

I am reading the json body as string and not as any bean in my service implementation method . Below is the sample

@POST
    @Path("/accounts/")
    public Account getAccount(String jsonBody) {
       //Business code goes here
    }

I am stuck with this for a while now . Can some one help

Try adding @Consumes("application/json;charset=utf-8") to your getAccount resource. You may also need to specify a @Produces annotation too with a content type and a charset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM