Jaxb2 "Expected elements are (none)" when unmarshalling a java object from a XML document

49 views Asked by At

I have a two schemas, schema1.xsd and schema2.xsd

schema1.xsd imports schema2.xsd

I'm able to generate two packages com.package1 and com.package2 through xjc (pom.xml configuration)

When I try to run the code below

    final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setClassesToBeBound(RootElement.class);
    marshaller.setContextPaths("com.package1");
    setMarshaller(marshaller);
    setUnmarshaller(marshaller);

I get the following error

Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.example.com/x/y", local:"root_element"). Expected elements are (none)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:712) ~[jaxb-runtime-2.3.8.jar:2.3.8]

The xml file starts with a root_element tag and the generated java class is annotated with XMLRootElement(name = "root_element")

I'm using jaxb2-maven-plugin and spring-oxm

Any idea why this error is being thrown?

0

There are 0 answers