I have a class annotated with jaxb annotations and I want to configure the unmarshaller to fail the unmarshalling if there are missing attributes.
Let's say, I'm having the below class, and I would like to fail the unmarshaling if the EventId attribute is missing from the xml, but instead, it is set to null.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "event")
public class Event {
@XmlAttribute(name = "EventId", required="true")
private Integer eventId;
...
}
Unmarshalling code:
JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[]{Events.class}, null);
StringReader xml = new StringReader(data);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setEventHandler(new DefaultValidationEventHandler());
unmarshaller.unmarshal(xml);
Am I missing something? Should I configure somehow the unmarshaller to fail if there are missing "required" attributes?
Thanks!