Xstream (Java) not correctly deserializing Xml string to object

dvfreal

New Member
I have the following XML string, and I'm trying to deserialize it to an object, but ultimate result is not correct.The XML string is:
\[code\]<Header><Sequence value=http://stackoverflow.com/"bbb-mySeq\"/><Session value=http://stackoverflow.com/"aaa-myValue\"/></Header>";\[/code\]The object that I'm trying to deserialize to is:\[code\]public class Header implements Serializable {private static final long serialVersionUID = 1L;private List<Session> sessions = new ArrayList<Session>();private List<Sequence> sequences = new ArrayList<Sequence>();public List<Session> getSession() { return sessions;}public void setSession(Session session) { this.sessions.add(session);}public List<Sequence> getSequence() { return sequences;}public void setSequence(Sequence sequence) { this.sequences.add(sequence); }}\[/code\]The Sequence object is:\[code\]public class Sequence implements Serializable {private static final long serialVersionUID = 1L;private String value;public String getValue() { return value;}public void setValue(String value) { this.value = http://stackoverflow.com/questions/13823918/value;}}\[/code\]The deserialization code is:\[code\] XStream xstream = new XStream(); xstream.alias("Header", Header.class); xstream.alias("Session", Session.class); xstream.alias("Sequence", Sequence.class); xstream.addImplicitCollection(Header.class, "sessions"); xstream.addImplicitCollection(Header.class, "sequences"); xstream.useAttributeFor(Session.class, "value"); xstream.useAttributeFor(Sequence.class, "value"); System.out.println("msg: " + msg); Header result = (Header) xstream.fromXML(msg);\[/code\]When I do a \[code\]toString()\[/code\] on the resulting object, I see:\[code\]Header [sessions=null, sequences=[Sequence [value=http://stackoverflow.com/questions/13823918/bbb-mySeq], Session [value=aaa-myValue]]]\[/code\]As you can see, there should be no Session in Sequences. Thanks in advance for any help.
 
Back
Top