Return-Path: Delivered-To: apmail-cxf-users-archive@www.apache.org Received: (qmail 82531 invoked from network); 2 Oct 2009 16:04:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Oct 2009 16:04:36 -0000 Received: (qmail 7430 invoked by uid 500); 2 Oct 2009 16:04:35 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 7370 invoked by uid 500); 2 Oct 2009 16:04:35 -0000 Mailing-List: contact users-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@cxf.apache.org Delivered-To: mailing list users@cxf.apache.org Received: (qmail 7360 invoked by uid 99); 2 Oct 2009 16:04:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Oct 2009 16:04:35 +0000 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [216.82.250.147] (HELO mail129.messagelabs.com) (216.82.250.147) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Oct 2009 16:04:22 +0000 X-VirusChecked: Checked X-Env-Sender: dk068x@att.com X-Msg-Ref: server-8.tower-129.messagelabs.com!1254499439!34115180!1 X-StarScan-Version: 6.1.3; banners=-,-,- X-Originating-IP: [144.160.112.25] Received: (qmail 24440 invoked from network); 2 Oct 2009 16:04:00 -0000 Received: from sbcsmtp3.sbc.com (HELO tlph064.enaf.dadc.sbc.com) (144.160.112.25) by server-8.tower-129.messagelabs.com with DHE-RSA-AES256-SHA encrypted SMTP; 2 Oct 2009 16:04:00 -0000 Received: from enaf.dadc.sbc.com (localhost.localdomain [127.0.0.1]) by tlph064.enaf.dadc.sbc.com (8.14.3/8.14.3) with ESMTP id n92G3xco026173 for ; Fri, 2 Oct 2009 11:03:59 -0500 Received: from td03xsmtp008.US.Cingular.Net (intexchapp01.us.cingular.net [135.179.64.42] (may be forged)) by tlph064.enaf.dadc.sbc.com (8.14.3/8.14.3) with ESMTP id n92G3tqj026014 for ; Fri, 2 Oct 2009 11:03:55 -0500 Received: from BD01XSMTP003.US.Cingular.Net ([135.163.18.44]) by td03xsmtp008.US.Cingular.Net with Microsoft SMTPSVC(6.0.3790.3959); Fri, 2 Oct 2009 11:03:55 -0500 Received: from BD01MSXMB018.US.Cingular.Net ([135.214.27.52]) by BD01XSMTP003.US.Cingular.Net with Microsoft SMTPSVC(6.0.3790.3959); Fri, 2 Oct 2009 09:03:54 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable x-cr-puzzleid: {7A612511-0369-460B-8D6F-7BC83750BED0} x-cr-hashedpuzzle: AC5o Az1K Bf1O CptU CzZf DXdn FBaP FpvZ Fu3v HMbz Ie/x Igpx JQUE KaxE LAeh Lmxe;1;dQBzAGUAcgBzAEAAYwB4AGYALgBhAHAAYQBjAGgAZQAuAG8AcgBnAA==;Sosha1_v1;7;{7A612511-0369-460B-8D6F-7BC83750BED0};ZABrADAANgA4AHgAQABhAHQAdAAuAGMAbwBtAA==;Fri, 02 Oct 2009 16:03:51 GMT;UgBFADoAIABIAG8AdwAgAHQAbwAgAG0AYQBrAGUAIABjAGwAZQBhAG4AIABqAHMAbwBuACwAIABpAG4AcwB0AGUAYQBkACAAbwBmACAAeABtAGwALQBpAHMAaAAgAGoAcwBvAG4APwA= Content-class: urn:content-classes:message Subject: RE: How to make clean json, instead of xml-ish json? Date: Fri, 2 Oct 2009 09:03:51 -0700 Message-ID: In-Reply-To: <00c001ca435b$e261ddf0$1f02050a@emea.progress.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: How to make clean json, instead of xml-ish json? thread-index: AcpDW/q7th7vBiQvSGKTuiO5NGN5JgAHMVrg References: <00c001ca435b$e261ddf0$1f02050a@emea.progress.com> From: "KARR, DAVID (ATTCINW)" To: X-OriginalArrivalTime: 02 Oct 2009 16:03:54.0533 (UTC) FILETIME=[F0E82550:01CA4379] X-Virus-Checked: Checked by ClamAV on apache.org > -----Original Message----- > From: Sergey Beryozkin [mailto:sberyozk@progress.com] >=20 > Note the reason "feature" is not dropped because you've add an > @XmlWrapperElement, with @XmlElement(name=3D"features") alone you can > get : > {"Item":{"features":[123,124],"description":"abc","id":1,"title":"item" > }} >=20 > The question is how to tell Jettision that 'feature' needs to appear as > 'features' on the output and that a wrapper 'features' needs > to be ignored. Expect some customizations to come in... Note that an even better result would be {"id":"1","description":"def","title":"abc","features":["123","456"]} This is the result I'm getting with the Jackson provider. I'd be fine with seeing if we can get the same with the Jettison provider, just so people have an easy choice, at least for these capabilities. (Curiously, if you're following my travails, I had the same annotations classloader issue with the Jackson annotations that I did with the CXF annotations, and putting the Jackson jars in APP-INF/lib resolved this.) > ----- Original Message ----- > From: "KARR, DAVID (ATTCINW)" > To: > Sent: Thursday, October 01, 2009 9:51 PM > Subject: RE: How to make clean json, instead of xml-ish json? >=20 >=20 > > -----Original Message----- > > From: Sergey Beryozkin [mailto:sberyozk@progress.com] > > > > Given this sample Item and Feature classes : > > > > @XmlRootElement > > public static class Item { > > private String description; > > @XmlElement > > public List features =3D new ArrayList(); > > private int id; > > private String title; > > > > public void setDescription(String description) { > > this.description =3D description; > > } > > > > public String getDescription() { > > return description; > > } > > > > public void setId(int id) { > > this.id =3D id; > > } > > > > public int getId() { > > return id; > > } > > > > public void setTitle(String title) { > > this.title =3D title; > > } > > > > public String getTitle() { > > return title; > > } > > } > > > > @XmlRootElement > > public static class Feature { > > private int id; > > > > public Feature() { > > > > } > > > > public Feature(int id) { > > this.id =3D id; > > } > > > > public void setId(int id) { > > this.id =3D id; > > } > > > > public int getId() { > > return id; > > } > > > > } > > > > The following test : > > > > @Test > > public void testIt2() throws Exception { > > JSONProvider p =3D new JSONProvider(); > > p.setSerializeAsArray(true); > > List keys =3D new ArrayList(); > > //keys.add("features"); > > p.setArrayKeys(keys); > > > > Item item =3D new Item(); > > item.setDescription("def"); > > item.features.add(new Feature(123)); > > item.features.add(new Feature(124)); > > item.setId(1); > > item.setTitle("abc"); > > > > ByteArrayOutputStream os =3D new ByteArrayOutputStream(); > > > > p.writeTo(item, (Class)Item.class, Item.class, > > Item.class.getAnnotations(), > > MediaType.APPLICATION_JSON_TYPE, new > > MetadataMap(), os); > > > > String str =3D os.toString(); > > System.out.println(str); > > } > > > > produces : > > > > > {"item":{"features":[{"id":123},{"id":124}],"description":"def","id":1, > > " > > title":"abc"}} > > > > (one can probably affect the ordering with JAXB annotations too so > that > > "description" is listed first) > > > > Can you please send me the source for Item and Feature classes ? >=20 > I assume your example here is using the default Jettison provider, > then? >=20 > In my current example, "features" is just a list of Strings, but an > example of a list of non-primitives is also worth exploring. >=20 > I believe what you're saying in this example is that I need to set > "serializeAsArray" to true, but leave "arrayKeys" as an empty list > (which makes me wonder what that property actually does). >=20 > For reference, here is my current Item class: >=20 > @XmlRootElement(name =3D "Item") > public class Item { > private String id; > private String title; > private String description; > private List features =3D new ArrayList(); >=20 > // This combination produces > "val". > @XmlElementWrapper(name =3D "features") > @XmlElement(name =3D "feature") > public List getFeatures() { return features; } > } >=20 > > In meantime, please see how Jackson provider can be registered : > > > http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resou > > r > > ces/jaxrs_jackson_provider/WEB-INF/beans.xml > > > > Will it produce JSON you expect ? >=20 > We'll see. If I still have issues with using Jettison, I'll try to > move > forward with using Jackson. >=20 > Thanks for your help. >=20 > > -----Original Message----- > > From: KARR, DAVID (ATTCINW) [mailto:dk068x@att.com] > > Sent: 01 October 2009 18:13 > > To: users@cxf.apache.org > > Subject: RE: How to make clean json, instead of xml-ish json? > > > > > -----Original Message----- > > > From: Sergey Beryozkin [mailto:sberyozk@progress.com] > > > Sent: Thursday, October 01, 2009 9:42 AM > > > To: users@cxf.apache.org > > > 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)" > > > To: > > > 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: users@cxf.apache.org > > > > 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: > > > > > > > > > > > > > > > def > > > > > > > > > > 123 > > > > > 456 > > > > > > > > > > 1 > > > > > abc > > > > > > > > > > > > > > > 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: > > > > > > > > > > > xmlns:util=3D"http://www.springframework.org/schema/util" > > > xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" > > > xmlns:jaxws=3D"http://cxf.apache.org/jaxws" > > > xmlns:jaxrs=3D"http://cxf.apache.org/jaxrs" > > > xmlns:cxf=3D"http://cxf.apache.org/core" > > > xsi:schemaLocation=3D" > > > 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"> > > > > > > > > > > > /> > > > > > > > > = resource=3D"classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" > /> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > class=3D"org.apache.cxf.jaxrs.provider.JSONProvider"> > > > > > > > > > > > > features > > > > > > > > > > > > > > > > > >