Saturday, 24 August 2013

to XML using XStream

to XML using XStream

I wanted to serialize and deserialize an instance of ObservableList.
The plan was the following:
ObservableList<Expense> data; //Contains Objects of the type Expense...
....
XStream xmlStream = new XStream(new DomDriver());
xmlStream.toXML(data);
This doesn't work, what didn't really confuse me. I ended doing something
like this:
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new
FileOutputStream(serializedFile)));
for (int i=0; i<data.size(); ++i) {
serialize = xmlStream.toXML(data.get(i));
dos.writeUTF(serialize);
}
dos.flush();
dos.close();
This worked well, but I have no idea, how I could deserialize this,
because I don't know, what the size of data will be. I heard of Iterators
and stuff, but how should I use one of them with this 3rd party library?
Do you have an answer or maybe a better idea? I would really appreciate
it. :)

No comments:

Post a Comment