Customizing error handling of JAXB unmarshall process
- by ekeren
Assuming I have a schema that describes a root element class Root that contains a List<Entry> where the Entry class has a required field name.
Here is how it looks in code:
@XmlRootElement
class Root{
@XmlElement(name="entry")
public List<Entry> entries = Lists.newArrayList();
}
@XmlRootElement
class Entry{
@XmlElement(name="name",required=true)
public String name;
}
If I supply the following XML for unmarshalling:
<root>
<entry>
<name>ekeren</name>
</entry>
<entry>
</entry>
</root>
I have a problem because the second entry does not contain a name. So unmarshall produces null.
Is there a way to customize JAXB to unmarshall a Root object that will only contain the "good" entry?