How do you create a POJO containing a list that the container has attributes?
Typically when creating a POJO of a list you do it the following way:
To represent the following XML structure:
<folder>
<messages>
<message>
<subject>XXXX</subject>
...
</message>
<message>
<subject>XXXX</subject>
...
</message>
</messages>
</folder>
@XmlRootElement(name = "folder")
public class Folder {
@XmlElement
private List<Message> messages;
...
}
@XmlRootElement(name = "message")
public class Message {
@XmlElement
private String subject;
...
}
But how do you represent a POJO when there are attributes at the messages tag? i.e.
<folder>
<messages total="45" start="3">
<message>
<subject>XXXX</subject>
...
</message>
<message>
<subject>XXXX</subject>
...
</message>
</messages>
</folder>
Do you create a POJO specifically for messages and then map a List of Message with an annotation of @XmlValue or something along those lines?
Thanks for your help guys.
The following approach could be used with any JAXB (JSR-222) implementation.
Messages
Using just the standard JAXB (JSR-222) APIs you will need to introduce a
Messagesclass to your model.Folder
Then you will need to modify your
Folderclass to reference the newMessagesclass.Message