Balaji V
Balaji V

Reputation: 956

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

Upvotes: 0

Views: 618

Answers (1)

fiw
fiw

Reputation: 756

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.

Upvotes: 1

Related Questions