I'm new to JAXB and have inherited a project which uses it to marshall/unmarshall xml - there is custom validation already written using various JAXB annotations - currently no schema is used.
I need to add some validation when unmarshalling to check that a given element only occurs once - from searching around this looks like it is usually achieved using "maxOccurs=1" within an xsd - so my question is can this be achieved using any JAXB validation annotation?
For example(shortened version for simplicity) - currently the last value, 'NameThree', gets unmarshalled but I want a validation error when more than 1 name element exists.
@XmlAccessorType(XmlAccessType.FIELD)
public class Person {
@XmlElement(name="NAME", required = true)
protected String name;
}
And xml file:
<Person>
<Name>NameOne</Name>
<Name>NameTwo</Name>
<Name>NameThree</Name>
</Person>
Thanks for any pointers.
Edit - for clarity, the element is not the root element. There are other elements(above is for illustration only)