Apache cxf Jax Rs编码问题

时间:2015-10-21 03:46:03

标签: apache jboss character-encoding jax-rs cxf

我正在使用Apache cxf的jaxrs。下面是xml配置

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

对于我的一些post方法,我发现双字节的charectors正在变形,并且显示为乱码的charectors并存储在数据库中。

我正在读取json主体作为字符串而不是我的服务实现方法中的任何bean。以下是样本

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

我现在已经坚持了一段时间。可以帮助一些人

1 个答案:

答案 0 :(得分:1)

尝试将@Consumes(“application / json; charset = utf-8”)添加到您的getAccount资源中。您可能还需要使用内容类型和字符集来指定@Produces注释。