问题
I have the following response created by CXF using JAX-RS:
{"ns1.CustomerInformationResponse":{
"@xsi.type":"ns1:CustomerInformationResponse",
"ns2.code":"SUCCESS",
"ns1.customer":{
"@xsi.type":"ns2:CustomerBaseDTO",
"ns2.login":"login1"
}
}}
And here is the relevant portion of my current context configuration:
<jaxrs:server address="http://${host}:${port}/rest/customer">
<jaxrs:serviceBeans>
<ref bean="customerManagementServiceImpl" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.apache.cxf.jaxrs.provider.AegisJSONProvider" />
</jaxrs:providers>
</jaxrs:server>
I would like to receive responses like the one above, without the namespace prefixes (i.e. ns1, ns2, etc...).
I have tried to add org.apache.cxf.interceptor.transform.TransformOutInterceptor
to cxf:outInterceptors
, but it did not help.
回答1:
In your beans.xml, you can specife the bean jsonProvider like below.
<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.AegisJSONProvider">
<property name="ignoreNamespaces" value="true" />
</bean>
Now Invoke the jsonProvider in the Context Configuration as below
<jaxrs:server address="http://${host}:${port}/rest/customer">
<jaxrs:serviceBeans>
<ref bean="customerManagementServiceImpl" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean ="jsonProvider" />
</jaxrs:providers>
</jaxrs:server>
来源:https://stackoverflow.com/questions/12998480/how-to-remove-namespace-prefixes-from-json-response-in-cxf-jax-rs