| Author |
Problems with Collection serialization
|
Vijaishanker bala
Ranch Hand
Joined: Sep 08, 2005
Posts: 82
|
|
hi, I am trying to serialize a collection of objects like in but when i open the created file, it appears as if only the last object is written, the remaining objects in the collection are not written...And when deserializing it asks to be deserialized as an object of type "ObjectProgram" and not an object of type "ArrayList"...Is there any other better way to serialize and deserialize a collection of objects using standard java apis. yes,"ObjectProgram" implements Serializable thanks Vijai
|
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." <br />Linus Torvalds
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
This should be fine. Let's see the de-serialization code.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Vijaishanker bala
Ranch Hand
Joined: Sep 08, 2005
Posts: 82
|
|
the code for Deserialization is as follows, The error thrown for this code is java.io.InvalidClassException: com.vijai.matrix.plugin.Schema.ObjectProgram; no valid constructor at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:379) at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:253) at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:453) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
|
 |
Vijaishanker bala
Ranch Hand
Joined: Sep 08, 2005
Posts: 82
|
|
The full code is as follows, the previous code snippets were taken at different times...contradicted between the serializing and Deserializing This is the actual code
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
You don't show the code for the class "ObjectProgram", but one of the requirements for deserialization of a class is that the superclass must either be Serializable itself, or must have a no-argument constructor. The error message is telling you that deserialization failed for an instance of ObjectProgram, not that the entire file contains a single ObjectProgram. Although the message isn't clear, I suspect what this is saying is that ObjectProgram's superclass is not serializable, and doesn't have a default constructor.
|
 |
Vijaishanker bala
Ranch Hand
Joined: Sep 08, 2005
Posts: 82
|
|
Thanks Earnest, It solved my problem. As a matter of fact, the derived class had a serializable implementation while the Super class did not have one.When I made the superclass to implement Serializable it worked fine. Vijai
|
 |
 |
|
|
subject: Problems with Collection serialization
|
|
|