XStream: Omit collection with XStreamImplicit

nbento

New Member
I'm trying to output a small object graph to JSON with XStream. Only output, no de-serializing required.The objects are very simple:\[code\]@XStreamAlias("players")public class Players { @XStreamImplicit private List<Player> players = new ArrayList<Player>(); public Players() { for (int i = 0; i < 5; ++i) { players.add(new Player("Player " + i)); } }}@XStreamAlias("player")public class Player { private String name; public Player(String name) { this.name = name; }}\[/code\]Luckily, the unnecessary list wrapper element is omitted in JSON:\[code\]{ players: { player: { name: "Player 4"}}}\[/code\]But unfortunately, only the last element is printed.I'm using XStream 1.4.2, intialized like that:\[code\]XStream xstream = new XStream(new JsonHierarchicalStreamDriver());xstream.setMode(XStream.NO_REFERENCES);xstream.aliasSystemAttribute(null, "class");xstream.autodetectAnnotations(true);String out = xstream.toXML(xstramAliasObject);\[/code\]As far as I can see the setup is similar to this question: XStream Alias of List root elements.What's wrong with my example?Thanks in advance!Regards, Michael
 
Top