[jdom-interest] Serialization Trouble through Inheritance
Björn Buchner
b.buchner at isys-software.de
Thu Aug 9 07:08:48 PDT 2012
Hi Folks,
I am using the JDOM 2.0.2 release and experienced some trouble when it
comes to serialization.
De-/serializing an Element object through the standard
ObjectOutput/InputStream is no problem. Trouble starts when I try to
deserialize an object of a class that inherits from Element.
It always ends with a InvalidClassException: no valid constructor.
Normally this indicates that JRE is missing a public default
constructor, but as you can see in the example below the subclass
has a default constructor.
Thanks in advance for your help
Example code:
public class MyElement extends Element {
private static final long serialVersionUID = -4220756491425652053L;
public MyElement() {
super();
}
public static void main(String ... args) throws IOException,
ClassNotFoundException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream outStream = new ObjectOutputStream(buffer);
MyElement element = new MyElement();
outStream.writeObject(element);
outStream.flush();
ObjectInputStream inStream = new ObjectInputStream(new
ByteArrayInputStream(buffer.toByteArray()));
element = (MyElement)inStream.readObject();
}
}
Result:
Exception in thread "main" java.io.InvalidClassException:
<packageremoved>; no valid constructor
at
java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147)
at
java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755)
at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at <packageremoved>.main(MyElement.java:29)
--
iSYS Software GmbH
Björn Buchner
Tel: +49 (0) 89 46 23 28-0 | Fax (0) 89 46 23 28-14
email: b.buchner at isys-software.de
Grillparzerstr. 10 | D-81675 Muenchen
www.isys-software.de
Sitz der Gesellschaft: München | HRB 111760
Geschaeftsfuehrer: Prof. Dr. Peter Mandl und Michael Sailer
More information about the jdom-interest
mailing list