> -----Original Message-----
> From: Sergey Beryozkin [mailto:[email protected]]
> Sent: Thursday, October 01, 2009 9:42 AM
> To: [email protected]
> Subject: Re: How to make clean json, instead of xml-ish json?
> 
> Hi David
> 
> sorry for a late reply, I was planning to reply later this evening.
> Setting a 'features' key should've made a difference but I will try
> your example just a bit later
> I'll get back to you asap
> 
> Apparently a Jackson provider shoud do easily enough.

Thanks.  I'll start diving into the Jackson documentation.

> ----- Original Message -----
> From: "KARR, DAVID (ATTCINW)" <[email protected]>
> To: <[email protected]>
> Sent: Thursday, October 01, 2009 5:35 PM
> Subject: RE: How to make clean json, instead of xml-ish json?
> 
> 
> > -----Original Message-----
> > From: KARR, DAVID (ATTCINW)
> > Sent: Thursday, October 01, 2009 9:28 AM
> > To: [email protected]
> > Subject: RE: How to make clean json, instead of xml-ish json?
> >
> > > -----Original Message-----
> > > From: KARR, DAVID (ATTCINW)
> > >
> > > I have a REST prototype using CXF that produces reasonable looking
> > XML,
> > > and almost reasonably looking JSON.  The JSON it produces is
> > "xml-ish".
> > >
> > > For instance, the sample XML I get is the following:
> > >
> > > <Item>
> > >  <description>def</description>
> > >  <features>
> > >   <feature>123</feature>
> > >   <feature>456</feature>
> > >  </features>
> > >  <id>1</id>
> > >  <title>abc</title>
> > > </Item>
> > >
> > > The JSON is this:
> > >
> > >
> >
>
{"Item":{"description":"def","features":{"feature":[123,456]},"id":1,"t
> > > i
> > > tle":"abc"}}
> > >
> > > A nicer JSON result would have been this:
> > >
> > >
> >
>
{"Item":{"description":"def","features":[123,456],"id":1,"title":"abc"}
> > > }
> > >
> > > Is it possible to modify just the JSON results, but still have the
> > "out
> > > of the box" XML results?
> >
> > Related to this, I noticed the "Dealing with JSON array
serialization
> > issues" section in the user guide.  I have a feeling this is telling
> me
> > that setting "serializeAsArray" and "arrayKeys" in my JSONProvider.
> > I'm
> > building a test for this now.  Even if this works, I'd have to say
> that
> > this documentation could use a clearer explanation of this, perhaps
> > with
> > more fully-elaborated examples.  The documentation for this is quite
> > brief.  Full examples showing "before" and "after" would be useful.
> > There is a link to another example that supposedly provides more
> info,
> > but it only shows the beans.xml file, without any elaboration or
> > example.
> 
> My change to "serializeAsArray" and "arrayKeys" in a JSONProvider
> didn't
> do anything. The JSON output didn't change.
> 
> The following are the relevant pieces of my beans.xml file:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans";
>        xmlns:util="http://www.springframework.org/schema/util";
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>    xmlns:jaxws="http://cxf.apache.org/jaxws";
>         xmlns:jaxrs="http://cxf.apache.org/jaxrs";
>         xmlns:cxf="http://cxf.apache.org/core";
>     xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> http://www.springframework.org/schema/util
> http://www.springframework.org/schema/util/spring-util-2.0.xsd
> http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
> http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
> http://cxf.apache.org/core http://cxf.apache.org/schemascore.xsd";>
> 
> <import resource="classpath:META-INF/cxf/cxf.xml" />
> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"
> />
> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
>     <import
> resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
> 
>     <jaxrs:server name="restcatalogserver" address="/rest">
>         <jaxrs:features>
>             <cxf:logging/>
>         </jaxrs:features>
>         <jaxrs:providers>
>             <ref bean="jsonProvider"/>
>         </jaxrs:providers>
> 
>         <jaxrs:serviceBeans>
>             <ref bean="catalog"/>
>         </jaxrs:serviceBeans>
>     </jaxrs:server>
> 
>     <bean id="jsonProvider"
> class="org.apache.cxf.jaxrs.provider.JSONProvider">
>         <property name="serializeAsArray" value="true"/>
>         <property name="arrayKeys">
>             <list>
>                 <value>features</value>
>             </list>
>         </property>
>     </bean>
>     <bean id="catalog" class="com.att.ecom.catalog.Catalog">
>     </bean>
> </beans>

Reply via email to