I'm trying to create a POJO for the following structure for deserializing an xml, which I cannot change whatsoever:
<Flat>
<Door>
<Type>Wood</Type>
</Door>
<Room>
<Size>10</Size>
<Unit>m2</Unit>
</Room>
<Room>
<Size>22</Size>
<Unit>m2</Unit>
</Room>
</Flat>
The door element is singular, but how many room elements will be provided in the flat element varies. I started with the code below but did not work (and I see why, as the "Room" isn't a sub-root element that has an array of room elements):
public class FlatModel {
@Element(name = "Door")
private DoorModel door;
@ElementList(name = "Room")
private List<RoomModel> roomList;
public FlatModel() {
}
public FlatModel(DoorModel door, List<RoomModel> roomList) {
//rest is the constructors and getter/setters
But I could not find any documentation nor any answered question on how to implement such a class. Any help is appreciated.
If possible you need to change your xml to include a parent element for Room, e.g. Rooms and this Rooms can be deserialize to your Java POJO as list of Room.
Example:
And the POJO would be