Annotation XmlElement is a JAXB 2 specification for representing XML as Java classes / objects and vice versa. JAXB 2 binding rules are mainly based on mapping XML schema definitions to Java classes. Elements that can occur several times through the XML Schema attribute maxOccurs="unbounded" or a value of maxOccurs greater than 1 in their containing type are by default represented as a list property (a Java.util.List element elements) or, alternatively, less often, as an indexed property using accessories such as getProp(int index) for the Prop name of the element.
Therefore, I would say that unless the specific requirements require otherwise, I would not use shell elements for the typical use case that you describe. One caveat is that you will need Java member names in the plural, whereas in XML you will need a single form. In your example, you need to avoid the Name Persons XML element for the signature of a Java method, such as List<Person> getPersons() , and you can use the @XmlElement(Name = Person) annotation to get the XML element in a single form instead.
There is a broader discussion of your question: XML, like SGML (a common superset of XML and HTML), is a text format for representing semi-structured data (it was originally designed to replace HTML, but it didnβt work), therefore, the type of data that SGML / XML was developed, by definition, insufficiently represented in the Java component, trying to closely match Java classes / objects with markup elements in general. Instead, the DOM view or another view for sequential access to markup elements, where the order of documents of elements of different types among themselves is observed, may be more natural. In fact, JAXB 1 had more complex mapping rules that could round the order of element documents. But it turned out that for the relatively simple data-oriented applications that XML is used in most cases, this did not help. Consequently, JAXB 2 was designed to more easily capture data-oriented uses such as yours.
source share