Reading list values using xstream

WaterDemon

New Member
I am working with \[code\]xstream\[/code\] to read some xml in the following format --\[code\]<Objects> <Object Type="System.DateTime" >1234</Object> <Property Name="Drive" Type="System.Management.Automation.PSDriveInfo">H</Property> <Object Type="System.DateTime" >8888</Object> </Objects>\[/code\]Basically under Objects tag there can be n number of Object Type and each Object Type can have n number of Property tags. So I have modelled by Java classes and the code to read it as follows --\[code\]class ParentResponseObject { List <ResponseObject>responseObjects = new ArrayList<ResponseObject>();}@XStreamAlias("Object")@XStreamConverter(value = http://stackoverflow.com/questions/12676638/ToAttributedValueConverter.class, strings = {"Value" })class ResponseObject { String Type; String Value; List <Properties> properties = new ArrayList<Properties>(); }@XStreamAlias("Property")@XStreamConverter(value = http://stackoverflow.com/questions/12676638/ToAttributedValueConverter.class, strings = {"Value" })class Properties { String Name; String Type; String Value;}public class MyAgainTest { public static void main (String[] args) throws Exception { String k1 = //collect the xml as string XStream s = new XStream(new DomDriver()); s.alias("Objects", ParentResponseObject.class); s.alias("Object", ResponseObject.class); s.alias("Property", Properties.class); s.useAttributeFor(ResponseObject.class, "Type"); s.addImplicitCollection(ParentResponseObject.class, "responseObjects"); s.addImplicitCollection(ResponseObject.class, "properties"); s.useAttributeFor(Properties.class, "Name"); s.useAttributeFor(Properties.class, "Type"); s.processAnnotations(ParentResponseObject.class); ParentResponseObject gh =(ParentResponseObject)s.fromXML(k1); System.out.println(gh.toString()); }}\[/code\]Using this code, I am able to populate the responseObjects List in the ParentResponseObject class. However, the properties list in the ResponseObject is always null, even though I am using the same technique in both the cases. Can anyone please help on getting this solved. Help on this is highly appreciated.
 
Back
Top