Reputation: 55
I am trying to run this code:
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Tags tags = (Tags) unmarshaller.unmarshal(new File("Tags.xml"));
However, I get this error:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"tags"). Expected elements are (none)
How can I prevent this exception from occuring? This is my root element:
@XmlRootElement(name = "tags")
Upvotes: 2
Views: 127
Reputation: 8272
JAXB doesn't know which classes should process.
JAXBContext jaxbContext = JAXBContext.newInstance(Tags.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Tags tags = (Tags) unmarshaller.unmarshal(new File("Tags.xml"));
Upvotes: 1