On 09/06/14 10:53, Sergey Beryozkin wrote:
On 08/06/14 21:56, Lambert, Michael wrote:I take that back. Its now encapsulating the payload in a wrapper object. There should not be a "userDataType" object wrapped around the object:{"userDataType":{"id":11,"createDate":"2014-06-08T12:39:19.284-04:00","updateDate":"2014-06-08T12:39:19.284-04:00","collectionDate":"2008-09-20T12:39:19.284-04:00","data":{"name":"WeightPounds","value":134},"dataSource":{"id":"453ba2"},"user":{"id":"0d8a7c33"}}}add dropRootElement=trueit should read: {"id":11,"createDate":"2014-06-08T12:39:19.284-04:00","updateDate":"2014-06-08T12:39:19.284-04:00","collectionDate":"2008-09-20T12:39:19.284-04:00","data":{"name":"WeightPounds","value":134},"dataSource":{"id":"453ba2"},"user":{"id":"0d8a7c33"}} Same with a returned collection. Its wrapping it an an anonymous root element: {"userDataCollectionType":{"userData":[{"id":"342a","createDate":"2014-06-08T14:46:44.658-04:00","updateDate":"2014-06-08T14:46:44.658-04:00","collectionDate":"2008-09-20T14:46:44.658-04:00","data":{"name":"WeightPounds","value":134},"dataSource":{"id":"453ba2"},"user":{"id":"0d8a7c33"}},{"id":"34234a","createDate":"2014-06-08T14:46:44.661-04:00","updateDate":"2014-06-08T14:46:44.661-04:00","collectionDate":"2008-09-20T14:46:44.661-04:00","data":{"name":"WeightPounds","value":134},"dataSource":{"id":"453ba2"},"user":{"id":"0d8a7c33"}}]}} {"userData":[{"id":"342a","createDate":"2014-06-08T14:46:44.658-04:00","updateDate":"2014-06-08T14:46:44.658-04:00","collectionDate":"2008-09-20T14:46:44.658-04:00","data":{"name":"WeightPounds","value":134},"dataSource":{"id":"453ba2"},"user":{"id":"0d8a7c33"}},{"id":"34234a","createDate":"2014-06-08T14:46:44.661-04:00","updateDate":"2014-06-08T14:46:44.661-04:00","collectionDate":"2008-09-20T14:46:44.661-04:00","data":{"name":"WeightPounds","value":134},"dataSource":{"id":"453ba2"},"user":{"id":"0d8a7c33"}}]}add dropCollectionWrapperElement=trueCan someone help end this madness? :-)Well, why don't you use Jackson ? Surely it will work well ? If you plan work with Jettison/CXF JSONProvider then you need to keep tuning it, it is a very simple implementation that needs hints. And lease bear in mind that some users want Java/CXF consumers to read the
and *p*lease bear in mind...
data back... Cheers, SergeyOn Sun, Jun 8, 2014 at 2:44 PM, Lambert, Michael <mich...@michaellambert.comwrote:I solved it but its non intuitive. I used the following block in my beans.xml content file: <jaxrs:server id="services" address="/"> <jaxrs:serviceBeans> <ref bean="userDataServiceImpl" /> </jaxrs:serviceBeans> <jaxrs:providers> <ref bean="jaxbProvider"/> <ref bean="jsonProvider"/> </jaxrs:providers> </jaxrs:server> <bean id="userDataServiceImpl" class="com.healthmedia.ws.service.userdata.v1.UserDataServiceImpl" /> <util:list id="xmlTypes"> <value>application/xml</value> <value>text/xml</value> <value>application/*+xml</value> <value>application/vnd.com.healthmedia.user-data-collection+xml;version=1.0</value> <value>application/vnd.com.healthmedia.user-data+xml;version=1.0</value> </util:list> <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"> <property name="unmarshallAsJaxbElement" value="true"/> <property name="marshallAsJaxbElement" value="true" /> <property name="produceMediaTypes" ref="xmlTypes"/> <property name="consumeMediaTypes" ref="xmlTypes"/> </bean> <util:list id="jsonTypes"> <value>application/json</value> <value>application/*+json</value> <value>application/vnd.com.healthmedia.user-data-collection+json;version=1.0</value> <value>application/vnd.com.healthmedia.user-data+json;version=1.0</value> </util:list> <bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider"> <property name="unmarshallAsJaxbElement" value="true"/> <property name="marshallAsJaxbElement" value="true" /> <property name="ignoreNamespaces" value="true"/> <property name="produceMediaTypes" ref="jsonTypes"/> <property name="consumeMediaTypes" ref="jsonTypes"/> </bean> It SEEMS though that I shouldnt have to jump thorugh hoops to get this working. Is there a reason why it shouldnt work out of the box? The fact that the JSONProvider need to be told about a JAXB implementation detail seems wrong to me. I also ran into a JSON namespace issue that I had to solve as well. Is there a better way to configure this? Thanks again, -Mike On Sun, Jun 8, 2014 at 2:15 PM, Lambert, Michael < mich...@michaellambert.com> wrote:I have written an example service to implement standards I am trying to stand up where I work. I want to do contract first development and so derive all artifacts from a predefined xml schema and wadl for rest services. The project generates the artifacts and I import those artifacts into an implementation project to write the sample code. I then overrode the media types that the JAXBElementProvider and JSONProvider operate on in my context file (bean.xml). When I attempt to access the implemented service using a curl statement the following error occurs: curl -X GET -H "Accept: application/vnd.com.healthmedia.user-data+json;version=1.0" http://localhost:8080/user-data-service/user-data/11 JAXBException occurred : unable to marshal type "com.healthmedia.ws.entity.userdata.v1.UserDataType" as an element because it is missing an @XmlRootElement annotation. unable to marshal type "com.healthmedia.ws.entity.userdata.v1.UserDataType" as an element because it is missing an @XmlRootElement annotation. I am really stuck can someone help? The sample code is on my github account: https://github.com/MacFlecknoe/service-repository-sample The schemas and wadl are in the schema project ( https://github.com/MacFlecknoe/service-repository-sample/tree/master/schema), the java artifacts are generated in the artifact project ( https://github.com/MacFlecknoe/service-repository-sample/tree/master/user-data/artifacts) and the implementation is in the user-data-service project ( https://github.com/MacFlecknoe/service-repository-sample/tree/master/user-data/service ) Thank you in advance! Michael Lambert
-- Sergey Beryozkin Talend Community Coders http://coders.talend.com/ Blog: http://sberyozkin.blogspot.com