Announcement Announcement Module
Collapse
No announcement yet.
Jaxb2Marshaller gives unexpected exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jaxb2Marshaller gives unexpected exception

    I'm using org.springframework.oxm.jaxb.Jaxb2Marshaller to marshal an object like this:

    Code:
    	<bean id="EAI" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    		<property name="contextPath" value="nz.co.telecom.dsm.umts_som"/>
    		<property name="schema" value="classpath:UMTS_SOMAdapter.xsd"/>
    	</bean>
    I wire this into my class and call the marshal method on it and get XML out that looks like this:
    Code:
    <ns2:createProductOrder xmlns:ns2="http://www.telecom.co.nz/EAI/UMTS_SOM">
        <productOrder>
            <customerOrderItems>
                <customerOrderItem>
                    <productUpdate>
    ...
    Now the other end of the process (over which I have no control) reported this as bad XML because there was no explicit or default namespace on the subtags. So I reproduced the problem using just jaxb2 (see http://www.nabble.com/default-namesp...html#a17140555)
    and found the problem was solved by a minor edit to the xsd file and regenerating the classes. The edit was just adding attributeFormDefault="qualified" elementFormDefault="qualified" to the schema tag.

    So this solved the problem for the direct call to jaxb2. But I want to use Spring, so I ran the same Spring code I had before (which had previously produced the same bad XML the JAXB2 had done until I fixed the xsd file).

    But now I get this:
    Code:
    org.springframework.oxm.jaxb.JaxbMarshallingFailureException: JAXB marshalling exception: null; nested exception is javax.xml.bind.MarshalException
     - with linked exception:
    [org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'productOrder'. One of '{"":productOrder}' is expected.]
    I'll admit I'm pretty inexperienced with xsd, but it seems as though Spring is doing something more than straight JAXB2 and it is something I don't want it to do. I notice that Jaxb2Marshaller actually gets wired with the xsd file and the direct calls to JAXB2 only need the package name. So is there some validation going on that is failing? That doesn't make a lot of sense because it was not failing before with the same xsd and the same objects.

    Any advice is much appreciated.

  • #2
    I did some more work with the JAXB2 code and found if I added a schema I got the same problem, so I guess Spring is doing that because I am wiring one in.
    Then I tried changing my wiring to the following:
    Code:
    <bean id="EAI" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    		<property name="contextPath" value="nz.co.telecom.dsm.umts_som"/>
    </bean>
    ie removed the schema reference. That worked fine and produced the right XML for me. So I conclude this is not a Spring problem, just my lack ob XSD knowledge. If you can figure the answer from this scanty info then I'm interested but I don't actually have anything to solve now and the rest belongs on the JAXB discussion.

    Comment

    Working...
    X