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:[email protected]]
Sent: 21 July 2009 19:51
To: [email protected]
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:
<jaxrs:server id="metaRegistryService" address="/">
<jaxrs:serviceBeans>
<ref bean="metaRegistryServiceBean" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProviderBean" />
</jaxrs:providers>
</jaxrs:server>
<bean id="metaRegistryServiceBean"
class="com.cisco.xmp.wap.core.service.metaregistry.MetaRegistryService"
/>
<util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
<entry key="http://xmp.cisco.com/wap/schemas/ui/Component"
value="" />
<entry key="http://xmp.cisco.com/wap/schemas/ui/Tree" value=""
/>
</util:map>
<util:list id="jsonTypes">
<value>application/json</value>
<value>application/jettison</value>
</util:list>
<bean id="jsonProviderBean"
class="org.apache.cxf.jaxrs.provider.JSONProvider">
<property name="namespaceMap" ref="jsonNamespaceMap" />
<property name="serializeAsArray" value="true" />
<property name="consumeMediaTypes" ref="jsonTypes" />
<property name="produceMediaTypes" ref="jsonTypes" />
</bean>
-Vinh
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: Tuesday, July 21, 2009 9:12 AM
To: [email protected]
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: '[email protected]'
Subject: RE: bad json response
Hi
How does the Java class representing <component/> 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:[email protected]]
Sent: 18 July 2009 20:36
To: [email protected]
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:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <component
xmlns="http://xmp.cisco.com/wap/schemas/ui/Component"
xmlns:ns2="http://xmp.cisco.com/wap/schemas/ui/Tree" id="Tree">
<properties>
<ns2:treeProperties>
<ns2:multiSelect>true</ns2:multiSelect>
<ns2:doubleClickOpen>false</ns2:doubleClickOpen>
<ns2:singleClickOpen>false</ns2:singleClickOpen>
<ns2:lazyLoad>false</ns2:lazyLoad>
</ns2:treeProperties>
<ns2:node>
<ns2:iconclass>myIconClass</ns2:iconclass>
</ns2:node>
</properties>
</component>
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.