Details
Description
I have a problem when deserializing an instance of the javax.swing.text.DefaultStyledDocument class.
The problem is not really while deserializing : some private fields of this JDK class are mentionned as "transient" fields (like this one : private transient Vector listeningStyles. So they are not serialized.
The problem starts when I use the deserialized object (with the 'fromXML' method) : those previous "transient" fields have not been initialized and their use via DefaultStyledDocument or other JDK classes methods raise a NullPointerException...
So I tried the unmarshal method to initialise those fields with the default constructor first, and then deserialize:
XStream xstream = new XStream();
DefaultStyledDocument doc = new DefaultStyledDocument();
String xml = xstream.toXML(doc);
DefaultStyledDocument tmpDoc = new DefaultStyledDocument();
doc = (DefaultStyledDocument) xstream.unmarshal(
new XppReader(new StringReader(xml)),
tmpDoc);
...but this code raise an exception (at the end of this message). Can someone tell me what is wrong with this code or give me a solution to serialize/deserialize a DefaultStyledDocument ?
Thanks in advance.
Sebastien
********************************************************
com.thoughtworks.xstream.converters.ConversionException: No such field javax.swing.text.DefaultStyledDocument.children
---- Debugging information ----
required-type : javax.swing.text.DefaultStyledDocument$SectionElement
cause-message : No such field javax.swing.text.DefaultStyledDocument.children
class : javax.swing.text.DefaultStyledDocument
message : No such field javax.swing.text.DefaultStyledDocument.children
line number : 4
path : /javax.swing.text.DefaultStyledDocument/buffer/root/children
cause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
-------------------------------
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(Unknown Source)
at com.thoughtworks.xstream.core.ReferenceByXPathUnmarshaller.convertAnother(Unknown Source)
at com.thoughtworks.xstream.converters.reflection.ReflectionConverter.unmarshal(Unknown Source)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(Unknown Source)
at com.thoughtworks.xstream.core.ReferenceByXPathUnmarshaller.convertAnother(Unknown Source)
at com.thoughtworks.xstream.converters.reflection.ReflectionConverter.unmarshal(Unknown Source)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(Unknown Source)
at com.thoughtworks.xstream.core.ReferenceByXPathUnmarshaller.convertAnother(Unknown Source)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(Unknown Source)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(Unknown Source)
at com.thoughtworks.xstream.XStream.unmarshal(Unknown Source)
********************************************************