I am using Xstream to serialize a Job object. He looks normal.
but deserialization, I have a problem:
Exception in thread "main" com.thoughtworks.xstream.io.StreamException: : only whitespace content allowed before start tag and not . (position: START_DOCUMENT seen .... @1:1) at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:78) at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:137) at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:130) at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:109) at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:94) at com.thoughtworks.xstream.io.xml.XppReader.<init>(XppReader.java:48) at com.thoughtworks.xstream.io.xml.XppDriver.createReader(XppDriver.java:44) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:853) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:845)
Has any of you helped solve this problem before?
So I did for serialization:
XStream xstream = new XStream(); Writer writer = new FileWriter(new File("model.xml")); writer.write(xstream.toXML(myModel)); writer.close();
I also try this:
XStream xstream = new XStream(); OutputStream out = new FileOutputStream("model.xml"); xstream.toXML(myModel, out);
For deserialization, I did this as follows:
XStream xstream = new XStream(); xstream.fromXML("model.xml");
XML structure:
<projectCar.CarImpl> <CarModel reference="../.."></CarModel> </projectCar.CarImpl>
If so, I would like to hear. Thanks in advance.
source share