There is xml with data:
<?xml version = '1.0' encoding = 'UTF-8'?> <ipm> <isomsg> <field id="24" value="697"/> <isomsg id="48"> <isomsg id="105"> <field id="1" value="222"/> <field id="2" value="3333"/> </isomsg> </isomsg> </isomsg> <isomsg> <field id="0" value="222"/> <isomsg id="3"> <field id="1" value="00"/> <field id="2" value="00"/> <field id="3" value="00"/> </isomsg> </isomsg> </ipm>
classes
public class Field { private String id; private String value; public String getId () { return id; } public void setId (String id) { this.id = id; } public String getValue () { return value; } public void setValue (String value) { this.value = value; } } public class Isomsg { private String id; private Field[] field; public String getId () { return id; } public void setId (String id) { this.id = id; } public Field[] getField () { return field; } public void setField (Field[] field) { this.field = field; } } public class Ipm { private Isomsg[] isomsg; public Isomsg[] getIsomsg () { return isomsg; } public void setIsomsg (Isomsg[] isomsg) { this.isomsg = isomsg; } }
I want to serialize into an object
XStream xstream = new XStream(); xstream.alias("ipm", Ipm.class); xstream.alias("isomsg", Isomsg.class); Object o = xstream.fromXML(FileManager.getContents(inputXMl.getAbsolutePath()));
I get
com.thoughtworks.xstream.converters.ConversionException: null : null ---- Debugging information ---- cause-exception : java.lang.NullPointerException cause-message : null class : java.lang.reflect.Field required-type : java.lang.reflect.Field converter-type : com.thoughtworks.xstream.converters.extended.JavaFieldConverter path : /ipm/isomsg/field line number : 4 class[1] : [Ltest.java.main.XmlGenerator.xml.Isomsg; converter-type[1] : com.thoughtworks.xstream.converters.collections.ArrayConverter class[2] : test.java.main.XmlGenerator.xml.Ipm converter-type[2] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter version : 1.4.7 ------------------------------- at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:71) at com.thoughtworks.xstream.converters.collections.ArrayConverter.unmarshal(ArrayConverter.java:55) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:474) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:406) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1185) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1169) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1040) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1031)
There are other serialization analogies. I am pretty much by analogy, but it does not work Tell me where was I wrong?