I have used a .xsd file to generate Java classes, and with an XML file, I need to unmarshall.
I am using this code :
JAXBContext objJAXBContext = JAXBContext.newInstance("my.test");
// create an Unmarshaller
Unmarshaller objUnmarshaller = objJAXBContext.createUnmarshaller();
FileInputStream fis = new FileInputStream("test.xml");
JAXBElement<Root> objMyRoot = (JAXBElement<Root>) objUnmarshaller.unmarshal(fis);
Root mRoot = objMyRoot.getValue();
and I am getting this error:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Root"). Expected elements are (none)
I have seen many solutions but nothing works in my project.
What i can try to do?
Your xml root is missing the namespace (uri) attribute.
You better try this on the XMLRootElement
...
@XmlRootElement(name = "root", namespace="")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With