5

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.

Ryan Ransford
  • 3,224
  • 28
  • 35
user1763152
  • 51
  • 1
  • 2

1 Answers1

3

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>
JBJ
  • 173
  • 1
  • 1
  • 15
  • 1
    Additionally, you may use the `attributesToElements` property to remove the `@` characters added on for the JSON properties created from XML attributes. – Ryan Ransford Apr 03 '13 at 18:27
  • I think the best solution i found on net after searching for hours.. thanks guys. – Arundev Jun 05 '17 at 12:36