Details
Description
Hello,
I have a class with a field of type org.jdom.Element. When I try to serialize that class it get properly serialized. But during de-serialization process I am getting the following exception.
%<--------------------------------------------------------------------------------------------------------------------------------------
Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: Could not call org.jdom.Element.readObject()
---- Debugging information ----
message : Could not call org.jdom.Element.readObject()
cause-exception : java.lang.UnsupportedOperationException
cause-message : null
class : TestClass
required-type : org.jdom.Element
path : /TestClass/element/org.jdom.Element
class : TestClass
required-type : org.jdom.Element
path : /TestClass/element/org.jdom.Element
-------------------------------
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.callReadObject(SerializationMethodInvoker.java:77)
at com.thoughtworks.xstream.converters.reflection.SerializableConverter.doUnmarshal(SerializableConverter.java:365)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:121)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:197)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:169)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:121)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:832)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:819)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:767)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:759)
at XMLUtilTest.main(XMLUtilTest.java:75)
Caused by: java.lang.UnsupportedOperationException
at com.thoughtworks.xstream.core.util.CustomObjectInputStream.read(CustomObjectInputStream.java:215)
at org.jdom.Element.readObject(Element.java:1340)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.callReadObject(SerializationMethodInvoker.java:73)
... 18 more
-------------------------------------------------------------------------------------------------------------------------------------- >%
I am using the following method for serialization,
String xmlString = new XStream(new JDomDriver()).toXML(new TestClass());
and if I deserialize the same xmlString using the following code,
TestClass test = (TestClass) new XStream(new JDomDriver()).fromXML(xmlString);
I am getting the above mentioned exception. If I make the field of type org.jdom.Element to transient no exception occurs.
Please provide your comment...
Best Regards
Arun K
Additionally the following is my class,
public class TestClass implements Serializable {
{ this.name = "arun"; this.rollNr = new Integer(1001); this.percentage = new BigDecimal("86.00"); this.totalMarks = new Double(80); this.element = new Element("test"); }private String name;
private Integer rollNr;
private BigDecimal percentage;
private Double totalMarks;
private org.jdom.Element element;
public TestClass()
public String getName()
{ return name; }public void setName(String name)
{ this.name = name; }public BigDecimal getPercentage()
{ return percentage; }public void setPercentage(BigDecimal percentage)
{ this.percentage = percentage; }public Integer getRollNr()
{ return rollNr; }public void setRollNr(Integer rollNr)
{ this.rollNr = rollNr; }public Double getTotalMarks()
{ return totalMarks; }public void setTotalMarks(Double totalMarks)
{ this.totalMarks = totalMarks; }public Element getElement()
{ return element; }public void setElement(Element element)
{ this.element = element; }}
and the serilized form is as below,
<TestClass>
<name>ARN</name>
<rollNr>1003</rollNr>
<percentage>89.50</percentage>
<totalMarks>899.0</totalMarks>
<element serialization="custom">
<org.jdom.Element>
<default>
<attributes>
<size>0</size>
<parent reference="../../../.."/>
</attributes>
<content>
<elementData>
<org.jdom.Text>
<value>Arun</value>
<parent class="org.jdom.Element"
reference="../../../../../.."/>
</org.jdom.Text>
<null/>
<null/>
<null/>
<null/>
</elementData>
<size>1</size>
<parent class="org.jdom.Element" reference="../../../.."/>
</content>
<name>new_test</name>
</default>
<string></string>
<string></string>
<byte>0</byte>
</org.jdom.Element>
</element>
</TestClass>