I have a Spring Roo app with some JPA entities, and I'm adding some REST API handlers.
I added a method annotated with @RequestHandler ; the method returns
com.sas.commons.rest.Container<com.sas.commons.res t.Link>. This was failing at runtime with a .JAXBException "nor any of its super class is known to this context" :
Both my Container and Link class have javax.xml.bind.annotation annotations, i.e. @XmlRootElementCode:org.springframework.http.converter.HttpMessageNotWritableException: Could not marshal [com.sas.commons.rest.Container@4c260132[name=links,elements=[com.sas.commons.rest.Link@75dca6d2[method=GET,rel=get,uri=/projects/2,href=http://localhost:1080/AppG...]]]]: null; nested exception is javax.xml.bind.MarshalException - with linked exception: [javax.xml.bind.JAXBException: class com.sas.commons.rest.Link nor any of its super class is known to this context.]
I tried to add my Container and Link to my applicationContext.xml JAXB marshaller bean
but this still resulted in the exception. I Googled some more and found some suggestions to addCode:<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <property name="classesToBeBound"> <util:list> <!-- other domain classes here... -> <value>com.sas.commons.rest.Container</value> <value>com.sas.commons.rest.Link</value> </util:list> </property> </bean>
to my Container class. This resolves the immediate problem, but this is not a general solution because this Container class is a generic class, and I don't know all the possible types that it will be instantiated with, and I can't list all of them ahead of time. (This annotation is documented use is for subclasses, and the author of a class cannot always enumerate all subclasses either!) In this case, Container will be put in a jar that other projects will use, so source code changes to add @XmlSeeAlso({YourClass.class}) are out of the question.Code:@XmlSeeAlso({Link.class})
This is my first foray into the wilds of Spring+JAXB so it is unclear how this all ties together, where and how these contexts are created and configured, etc.
What is the correct way to generalize this so Spring O/X can marshal a Container<MyType> and a Container<YourType> when my Container does not know anything about MyType or YourType?
(Sorry if Roo is the wrong forum for this - this was my starting point for this app, and I was relying on it generating the bindings and configuration stuff for me.)
thanks


Reply With Quote
