tags:

views:

41

answers:

1

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

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

      <player>
         <name>Shaq</name>
         <age>33</age>
      </player>
   </players>
</team>

What I'd like is to not have the Players class as it doesn't add any value.

I tried just removing the Players class and adding the annotation below to the Team class but it didn't work. I think JAXB is expecting the <Player> elements to be directly one level below Team.

Any ideas?

@XmlElement(name = "Player")
protected List<Player> players;
+3  A: 

You need to add the @XmlElementWrapper annotation:

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