How can one ignore Unexpected element situation in JAXB ans still get all other kind of javax.xml.bind.UnmarshalException?
obj = unmler.unmarshal(new StringReader(xml))
Notice i still want to get the obj result of the xml parsing.
How can one ignore Unexpected element situation in JAXB ans still get all other kind of javax.xml.bind.UnmarshalException?
obj = unmler.unmarshal(new StringReader(xml))
Notice i still want to get the obj result of the xml parsing.
The solution.
In JAXB implementing ValidationEventHandler like so:
class CustomEventHandler implements ValidationEventHandler{
public boolean handleEvent(ValidationEvent evt) {
System.out.println("Event Info: "+evt);
if(evt.getMessage().contains("Unexpected element"))
return true;
return false;
}
}
Then
Unmarshaller u = ...;
u.setEventHandler(new CustomValidationEventHandler() );
u.unmarshal(new StringReader(xml));