Resteasy delegates XML parsing and writing to JAXB.  It does a little 
extra work to make things smoother but thats it.  You can't just stuff a 
GenericEntity within your XML documents and expect it to work.  It 
won't.  You should just try to get this working with regular JAXB code 
first and take RESTEasy out of the equation.

You can take a look at @XmlAnyElement, but I'm not sure if you'll be 
able to use this with Resteasy.  This is because Resteasy creates the 
JAXBContext and populates it only with the type returned by the JAX-RS 
method, or whats defined in the GenericEntity.  You'll have to create a 
ContextResolver<JAXBContext> that acts as a factory for your JAXBContext 
and populate it with the appropriate classes.

On 6/5/2013 4:35 PM, Mike Miller wrote:
> Running  RestEasy 2.3.5
> We are looking at exposing many of our EJB services thru RestEasy.   One
> of our thoughts is to return a common object that contains a reference
> to the resource or list of resources.   The object would look like
> below, where the resource or list of resources would be saved in the
> messageObject field.   This fails when Resteasy tries to find the
> correct message writer.
> *package* rest;
> *import* javax.xml.bind.annotation.XmlElement;
> *import* javax.xml.bind.annotation.XmlRootElement;
> @XmlRootElement(name = "RestfulResponse")
> *public* *class* RestfulResponse {
> *private**long*statusCode;
> *private*String statusDescription;
> *private*Object messageObject;
> *private*String excpDetails;
> @XmlElement(name="StatusCode")
> *public**long*getStatusCode() {
> *return*statusCode;
> }
> *public**void*setStatusCode(*long*statusCode) {
> *this*.statusCode= statusCode;
> }
> @XmlElement(name="StatusDescription")
> *public*String getStatusDescription() {
> *return*statusDescription;
> }
> *public**void*setStatusDescription(String statusDescription) {
> *this*.statusDescription= statusDescription;
> }
> @XmlElement(name="ExceptionDetails")
> *public*String getExcpDetails() {
> *return*excpDetails;
> }
> *public**void*setExcpDetails(String excpDetails) {
> *this*.excpDetails= excpDetails;
> }
> @XmlElement(name="Response")
> *public*Object getMessageObject() {
> *return*messageObject;
> }
> *public**void*setMessageObject(Object messageObject) {
> *this*.messageObject= messageObject;
> }
> }
> I tried adjusting my resource method to use the GenericEntity class but
> must have gotten that wrong, see exception below.
> @GET
> @Produces({"application/json", "application/xml"})
> *public*RestfulResponse findAll(@QueryParam(BaseResource./OFFSET/)
> @DefaultValue("0") String offset, @QueryParam(BaseResource./LIMIT/)
> @DefaultValue("10") String limit)
> {
> List<EnvironmentBean> list = *null*;
> EnvironmentServiceLocal envSvc =
> Services./get/(EnvironmentServiceLocal.*class*);
> RestfulResponse response = *new*RestfulResponse();
> *try*{
> *if*(isRetrieveAllAllowed()) {
> list = _envSvc.findAll()_;
> } *else*{
> validatePaginationParms(offset, limit);
> list = _envSvc.find(__paginationParms__.get(BaseResource._/_OFFSET_/_),
> __paginationParms__.get(BaseResource._/_LIMIT_/_))_;
> }
> } *catch*(FinderException e) {
> response.setStatusCode(404);
> *return*response;
> }
> response.setStatusCode(200);
> GenericEntity<List<EnvironmentBean>> entity =
> *new*GenericEntity<List<EnvironmentBean>>(list) {};
> response.setMessageObject(entity);
> //response.setMessageObject(list);
> *return*response;
> }
> org.jboss.resteasy.plugins.providers.jaxb.JAXBMarshalException:
> javax.xml.bind.MarshalException
> - with linked exception:
> [javax.xml.bind.JAXBException: rest.EnvironmentResource$1 nor any of its
> super class is known to this context]
>          at
> org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:148)
>          at
> org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:117)
>          at
> org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.write(GZIPEncodingInterceptor.java:104)
>          at
> org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:123)
>          . . .
> This seems to work okay if I use the javax.ws.rs.core.Response class and
> set the entities in there.  We wanted the option to return some
> additional ‘metadata’ about the requests if appropriate, like a total
> count in a metadata field somewhere when getting a list of resources.
> Is there a better way to do what we are trying to do?
> Just setting the messageObject to the list reference gives exception:
> JAXBException: java.util.ArrayList nor any of its super class is known
> to this context.
>
>
> ------------------------------------------------------------------------------
> How ServiceNow helps IT people transform IT departments:
> 1. A cloud service to automate IT design, transition and operations
> 2. Dashboards that offer high-level views of enterprise services
> 3. A single system of record for all IT processes
> http://p.sf.net/sfu/servicenow-d2d-j
>
>
>
> _______________________________________________
> Resteasy-users mailing list
> Resteasy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/resteasy-users
>

-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to