Search code examples
javajaxbeclipselinkpackagemoxy

EclipseLink MOXy exception due to package structure


I have this bindings file

<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="com">
<java-types>
    <java-type name="com.test.Root">
        <xml-root-element name="root"/>
        <java-attributes>
            <xml-element java-attribute="element" xml-path="element" type="com.Element"/>
        </java-attributes>
    </java-type>
    <java-type name="com.Element"></java-type>
</java-types>

The package structure and the class location are as can be read off this bindings file. When I unmarshall I get the following exception. Can somebody tell me why and how I can solve the problem? I don't want to change my package structure.

JAXBException: The java-type with package [com.test] is not allowed in the bindings file keyed on package [com].

Solution

  • You need to have one binding file per package. BTW when you specify the package name in the xml-bindings element you don't need to fully qualify the name on the java-type element.