History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-449
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Arun
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
XStream

Cannot deserialize a class with org.jdom.Element

Created: 15/Nov/07 01:53 AM   Updated: 30/Nov/07 07:09 PM
Component/s: Core
Affects Version/s: 1.2.1
Fix Version/s: 1.2.2

JDK version and platform: Java 1.4.2_08


 Description  « Hide
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



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Arun - 15/Nov/07 02:07 AM
Additionally the following is my class,

public class TestClass implements Serializable {
private String name;
private Integer rollNr;
private BigDecimal percentage;
private Double totalMarks;
private org.jdom.Element element;
public TestClass() { this.name = "arun"; this.rollNr = new Integer(1001); this.percentage = new BigDecimal("86.00"); this.totalMarks = new Double(80); this.element = new Element("test"); }
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>


Arun - 29/Nov/07 05:10 AM
Hi All,

I checked the same with XStream version 1.2.2 and it seems to be working. I checked the change log for major/minor fixes, but couldn't find any references. Can anybody provide some references for the problem.

Arun


Joerg Schaible - 30/Nov/07 07:08 PM
Difficult to say now. It might have been one of the things we changed to support the field sorting. The problem with the reported exception is, that it normally hides the real problem, why readObject failed in first place. The error message "could not call readObject" is somewhat misleading here.

Joerg Schaible - 30/Nov/07 07:09 PM
Corrected fixed version.