Announcement Announcement Module
Collapse
No announcement yet.
Spring, Roo,and JAXBException: X nor any of its super class is known to this context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring, Roo,and JAXBException: X nor any of its super class is known to this context

    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" :

    Code:
    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.]
    Both my Container and Link class have javax.xml.bind.annotation annotations, i.e. @XmlRootElement

    I tried to add my Container and Link to my applicationContext.xml JAXB marshaller bean
    Code:
       <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>
    but this still resulted in the exception. I Googled some more and found some suggestions to add

    Code:
    @XmlSeeAlso({Link.class})
    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.

    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

  • #2
    I'm moving this thread to the Web Services forum which is probably a better fit;
    see Spring, Roo,and JAXBException: X nor any of its super class is known to this context there.

    Comment

    Working...
    X