xStream doesn't work correct with list and attributes

dreweasland

New Member
I'm trying to make some objects of a XML file. But i'm doing something wrong, this is the method where I put in the xml file:\[code\] XStream x = new XStream(); XML v = (XML) x.fromXML("<maxi-xml><name>World League</name><type>15</type><season>33</season><date>2012-05-27T18:00:00+02:00</date><arenaId>2191</arenaId><nationId>4</nationId><regionId>85</regionId><standings>2</standings><attendance>20000</attendance><meteo>3</meteo><status>3</status><event id=8228607/><event id=8228608/><event id=8228609/><event id=8228610/><event id=8228611/><event id=8228612/><event id=8228613/><event id=8228614/><event id=8228615/><event id=8228616/></maxi-xml>"); System.out.println("versie" + v.toString());\[/code\]this is the xml file:\[code\]<maxi-xml><name>National League 2.1 Nederland</name><type>15</type><season>33</season><date>2012-05-27T18:00:00+02:00</date><arenaId>2191</arenaId><nationId>4</nationId><regionId>85</regionId><standings>2</standings><attendance>20000</attendance><meteo>3</meteo><status>3</status><event id="8228607"/><event id="8228608"/><event id="8228609"/><event id="8228610"/><event id="8228611"/><event id="8228612"/>\[/code\]And this are the classes that i'm using:Competition class:\[code\] @XStreamAlias("maxi-xml") public class Competition { String name; int type; int season; Date date; int arenaId; int nationId; int regionId; int standings; int attendance; int meteo; int status; @XStreamImplicit ArrayList<Event> event; public Competition( String name, int type, int season, Date date, int arenaId, int nationId, int regionId, int standings, int attendance, int meteo, int status, ArrayList<Event> event) { this.name = name; this.type = type; this.season = season; this.date = date; this.arenaId = arenaId; this.nationId = nationId; this.regionId = regionId; this.standings = standings; this.attendance = attendance; this.meteo = meteo; this.status = status; this.event = event; } }\[/code\]The event class:\[code\]public class Event { @XStreamAsAttribute int id; public Event(int id) { this.id = id; }}\[/code\]Someone has any idee what I'm doing wrong?This is what I'm get when I do the reverse way:With this piece of code:\[code\] XStream x = new XStream(); ArrayList<Events> list = new ArrayList<Events>(); list.add(new Events(16)); list.add(new Events(1364)); list.add(new Events(1365)); list.add(new Events(1234)); list.add(new Events(5679)); XML xml = new XML("something", 1, 22, new Date(), 2, 2, 2, 2, 232434, 1, 3, list); String s = x.toXML(xml); System.out.println(s);<Competition> <name>something</name> <type>1</type> <season>22</season> <date>2012-06-01 09:18:27.161 UTC</date> <arenaId>2</arenaId> <nationId>2</nationId> <regionId>2</regionId> <standings>2</standings> <attendance>232434</attendance> <meteo>1</meteo> <status>3</status> <event> <Event> <id>16</id> </Event> <Event> <id>1364</id> </Event> <Event> <id>1365</id> </Event> <Event> <id>1234</id> </Event> <Event> <id>5679</id> </Event> </event></Competition>\[/code\]
 
Back
Top