|
From: Bill B. <bb...@re...> - 2008-10-09 22:50:27
|
I'm not even sure you can do that with JAXB, that is, have a Generic as a @XmlRootElement that has an attribute that returns an arbitrary JAXB annotated object. I would try implementing what you're doing with manual JAXB to see if it actually works. The eating of the error is a problem though. (I thought I had cleaned that all up :( ) BTW: Here's the test case for GenericEntity: http://resteasy.svn.sourceforge.net/viewvc/resteasy/tags/RESTEASY_JAXRS_1_0_BETA_8/resteasy-jaxrs/src/test/java/org/jboss/resteasy/test/finegrain/resource/GenericEntityTest.java?revision=347&view=markup Bill Mike Chack (mchack) wrote: > Thanks for the response. Figured you would have had a solution. I gave > it a try and I get a 500 response with no visible exception thrown. Not > sure if I am doing something dumb here or abusing the use of > GenericEntity > > @GET > @Produces("text/xml") > @RolesAllowed({"admin","super","user","mainuser"}) > @Path("/test") > public Response getSessionXmlTest() > { > Session session = new Session(SecurityFilter.getCurrentToken()); > > RestResponse status = new RestResponse("Session creation ok - > expires at - " + SecurityFilter.getExpirationTime()); > > RestResponseWrapper1<Session> wrapper = new > RestResponseWrapper1<Session>(status,session); > > GenericEntity<RestResponseWrapper1<Session>> ge = new > GenericEntity<RestResponseWrapper1<Session>>(wrapper){}; > > Response response = > Response.ok(ge,MediaType.TEXT_XML_TYPE).build(); > return response; > } > > @XmlRootElement(name = "ctbuapi") > public class RestResponseWrapper1<T> { > > private T result; > > RestResponse response = new RestResponse(); > > > public RestResponseWrapper1() > { > > } > > public RestResponseWrapper1(RestResponse response,T result) > { > this.response = response; > this.result = result; > } > > public RestResponse getResponse() { > return response; > } > > public void setResponse(RestResponse response) { > this.response = response; > } > > public T getResult() { > return result; > } > > public void setResult(T session) { > this.result = session; > } > > > } > > Mike Chack > > > -----Original Message----- > From: Bill Burke [mailto:bb...@re...] > Sent: Thursday, October 09, 2008 7:47 AM > To: Mike Chack (mchack) > Cc: res...@li... > Subject: Re: [Resteasy-developers] Generics Support > > See GenericEntity. > > Mike Chack (mchack) wrote: >> I was wondering if the following pattern is supported, don't think so >> but I may be missing something. >> >> >> >> I would like to have a generic class wrap all my REST responses. >> >> >> >> @GET >> >> @Path(/somepath) >> >> public GenericWrapper someMethod() >> >> { >> >> ResponseObject response = New ResponseObject(); >> >> return new GenericWrapper<response>(response); >> >> >> >> } >> >> >> >> The ResponseObject extends BasicResponse and is also annoted with > JAX-B >> @XmlRootEntity. >> >> >> >> >> >> @XmlRootEntity >> >> public class GenericWrapper<T extends BasicResponse> >> >> { >> >> >> >> String commondata; >> >> String othercommondata; >> >> String resultcode; >> >> ................ >> >> >> >> T response; >> >> >> >> public GenericWrapper(T response) >> >> { >> >> this.response = response; >> >> } >> >> } >> >> >> >> This way it simplifes the number of concrete classes needed for >> different response types. I don't think this works. Is there another >> pattern for this or is it reasonable for the framework to examine the > >> generics definition and search out the classes that extend > BasicResponse >> that have JAX-B annotations so proper marshalling can occur? >> >> >> >> thanks >> >> *Mike Chack* >> *O: +1 408.526.4639* >> *M: +1 408.504.6594* >> *mc...@ci...* >> >> >> >> >> > ------------------------------------------------------------------------ >> > ------------------------------------------------------------------------ > - >> This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge >> Build the coolest Linux based applications with Moblin SDK & win great > prizes >> Grand prize is a trip for two to an Open Source event anywhere in the > world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> >> >> > ------------------------------------------------------------------------ >> _______________________________________________ >> Resteasy-developers mailing list >> Res...@li... >> https://lists.sourceforge.net/lists/listinfo/resteasy-developers > -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |