Customizing error handling of JAXB unmarshall process

Posted by ekeren on Stack Overflow See other posts from Stack Overflow or by ekeren
Published on 2010-05-04T14:51:04Z Indexed on 2010/05/05 7:18 UTC
Read the original article Hit count: 283

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about jaxb