Using JAXB and skipping an item

We have XML as shown below. We have the corresponding Team, Players, and Player Java classes. We use JAXB to untie XML.

<team> <players> <player> <name>Le Bron</name> <age>23</age> </player> <player> <name>Shaq</name> <age>33</age> </player> </players> </team> 

I wish there was no Players class as it does not add any value.

I tried just removing the Players class and adding the annotation below to the Team class, but that didn't work. I think JAXB expects the <Player> elements to be at the same level below the Command.

Any ideas?

 @XmlElement(name = "Player") protected List<Player> players; 
+4
source share
1 answer

You need to add @XmlElementWrapper annotation:

 @XmlElementWrapper(name = "Players") @XmlElement(name = "Player") protected List<Player> players; 
+4
source

Source: https://habr.com/ru/post/1307960/


All Articles