Return-Path: Delivered-To: apmail-cxf-users-archive@www.apache.org Received: (qmail 5274 invoked from network); 22 Jul 2009 11:55:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Jul 2009 11:55:42 -0000 Received: (qmail 3079 invoked by uid 500); 22 Jul 2009 11:56:46 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 2986 invoked by uid 500); 22 Jul 2009 11:56:46 -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 2976 invoked by uid 99); 22 Jul 2009 11:56:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Jul 2009 11:56:46 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Jul 2009 11:56:36 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1MTaQh-00066Q-Lz for users@cxf.apache.org; Wed, 22 Jul 2009 04:56:15 -0700 Message-ID: <24604907.post@talk.nabble.com> Date: Wed, 22 Jul 2009 04:56:15 -0700 (PDT) From: Sergey Beryozkin To: users@cxf.apache.org Subject: RE: bad json response In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: sergey.beryozkin@iona.com References: <24590780.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org Hi I can not reproduce it at the moment. I've created a test which reads exactly the same XML you posted like this : @Test public void test() { InputStream is = getClass().getResourceAsStream("book.xml"); JAXBContext context = JAXBContext.newInstance(new Class[]{Component.class}); Unmarshaller um = context.createUnmarshaller(); JAXBElement jaxbEl = um.unmarshal(new StreamSource(is), Component.class); Map namespaceMap = new HashMap(); namespaceMap.put("http://xmp.cisco.com/wap/schemas/ui/Component", ""); namespaceMap.put("http://xmp.cisco.com/wap/schemas/ui/Tree", ""); JSONProvider p = new JSONProvider(); p.setSerializeAsArray(true); p.setNamespaceMap(namespaceMap); ByteArrayOutputStream os = new ByteArrayOutputStream(); p.writeTo(jaxbEl, (Class)JAXBElement.class, JAXBElement.class, JAXBElement.class.getAnnotations(), MediaType.APPLICATION_JSON_TYPE, new MetadataMap(), os); String s = os.toString(); System.out.println(s); } it outputs : {"component":{"@id":"Tree","properties":{"treeProperties":{"multiSelect":true,"doubleClickOpen":false,"singleClickOpen":false,"lazyLoad":false},"node":{"iconclass":"myIconClass"}}}} I created Component, Properties, TreeProperties and Node classes using the posted XML as the source so I might've missed some specifics but I think the problem is really to do with the fact that for some reasons ignorable whitespaces have been captured somehow during the initial read and they trick Jettison into outputting these BadgerFish notation like '$' symbols (thanks to dejan for explaining it to me). Can you please send me the actual XML file ? I created mine on Windows, so may be in your case it has some special characters or something. Also, is it how your read XML into JAXBElement ? I tried reading it into DOM first and using Unmarshaller.unmarshall(Node node, Class) too, no difference cheers, Sergey Sergey Beryozkin-2 wrote: > > Hi Vinh, > > Ok, it's a JAXBElement which is being returned...I'll try to reproduce > the problem, > cheers, Sergey > > -----Original Message----- > From: Vinh Nguyen (vinguye2) [mailto:vinguye2@cisco.com] > Sent: 21 July 2009 19:51 > To: users@cxf.apache.org > Subject: RE: bad json response > > Hi Sergey, > > Sorry for the late reply. I'm using XSDs to define the object models, > generate the Java classes using standard JAXB, load data from XML files, > and unmarshal to Java classes previously generated. > > The resource implementation looks like this: > > @Path("/metaregistry") > public class MetaRegistryService { > @GET > @Path("/{objectID}") > @Produces({"application/json", "application/xml"}) > public JAXBElement getMetaObject(@PathParam("objectID") String > objectID) > throws WebApplicationException { > // Simply load the XML file with the given objectID, and > ummarshal to the JAXB class. > JAXBElement xmlObj = ...; > return xmlObj; > } > } > > My beans.xml looks like this: > > > > > > > > > > class="com.cisco.xmp.wap.core.service.metaregistry.MetaRegistryService" > /> > > value="" /> > /> > > > application/json > application/jettison > > class="org.apache.cxf.jaxrs.provider.JSONProvider"> > > > > > > > -Vinh > > > -----Original Message----- > From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com] > Sent: Tuesday, July 21, 2009 9:12 AM > To: users@cxf.apache.org > Subject: RE: bad json response > > > Can you please give me more info about this issue ? > > cheers, Sergey > > Sergey Beryozkin-2 wrote: >> >> Actually, you did say your data are in the XML file. >> So can you please post a sample resource class with a method showing >> how the data is being returned ? >> >> Just would like to see a bit better how JSONProvider does (eventually) > >> start working. >> >> Thanks, Sergey >> >> -----Original Message----- >> From: Sergey Beryozkin >> Sent: 19 July 2009 16:37 >> To: 'users@cxf.apache.org' >> Subject: RE: bad json response >> >> Hi >> >> How does the Java class representing look like ? >> JSONProvider uses Jettison which is a STAX parser, so JAXB just >> streams the events and jettison reacts by converting them into JSON > sequences. >> Perhaps some JAXB annotation confuses Jettison... >> >> Thanks, Sergey >> >> -----Original Message----- >> From: Vinh Nguyen (vinguye2) [mailto:vinguye2@cisco.com] >> Sent: 18 July 2009 20:36 >> To: users@cxf.apache.org >> Subject: bad json response >> >> Hi, >> I've implemented a REST service. I have data in an XML file, use >> standard JAXB, and configured >> org.apache.cxf.jaxrs.provider.JSONProvider >> in my beans.xml to convert the JAXB objects to JSON. >> >> But when I visually inspect the JSON response, there seems to be >> name-value entries appearing like "$":"\n ". Should these be >> there? I assume the XML parser used by CXF should have already >> stripped out these unnecessary white spaces (i.e. carriage returns) >> before passing to the JSON converter. >> >> My XML looks like: >> >> > xmlns="http://xmp.cisco.com/wap/schemas/ui/Component" >> xmlns:ns2="http://xmp.cisco.com/wap/schemas/ui/Tree" id="Tree"> >> >> >> true >> false >> false >> false >> >> >> myIconClass >> >> >> >> >> The JSON response is coming as: >> >> > {"component":{"@id":"Tree","properties":{"treeProperties":{"multiSelect" >> > :true,"doubleClickOpen":false,"singleClickOpen":false,"lazyLoad":false," >> $":"\n "},"node":{"iconclass":"myIconClass","$":"\t\t\t >> \n "}}}} >> >> The $ property seems to appear after each corresponding element >> definition in the XML. Any idea how to get rid of these "$" > properties? >> On the client side, I'm using Dojo JSONPATH utils, and it's failing to > >> process the JSON string. >> >> Thanks, >> -Vinh >> >> >> > > -- > View this message in context: > http://www.nabble.com/bad-json-response-tp24551156p24590780.html > Sent from the cxf-user mailing list archive at Nabble.com. > > > -- View this message in context: http://www.nabble.com/bad-json-response-tp24551156p24604907.html Sent from the cxf-user mailing list archive at Nabble.com.