| Author |
Problem with Serialization / Deserialization
|
Jan Groth
Ranch Hand
Joined: Feb 03, 2004
Posts: 456
|
|
Hello, I have a problem with my first steps in Serialization / Deserialization. Scenarion 1: - Create a HashSet - fill it with Integer objects - serialize it to file -> ok. - deserialize it from file - read HashMap -> ok. Scenarion 2, almost the same code - Create a HashSet, - fill it with trivial objects ("SerObject", only one String member) - serialize it to file - deserialize it from file -> ClassNotFoundException SerObject. can someone please point me in the right direction? many thanks, Jan.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
This sounds like a common misconception about what serialization does: the SerObject class file has to be available on the classpath of the program that deserializes the file. The class definition isn't serialized, only the objects themselves.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jan Groth
Ranch Hand
Joined: Feb 03, 2004
Posts: 456
|
|
Hello Ernest, thanks for your answer. I forgot to mention that I've put the SerObject's class definition into the deserialization client's package. (Serializer and Deserializer are running on different VMs) So that's probably not causing the fault... Jan
|
 |
Philip Heller
author
Ranch Hand
Joined: Oct 24, 2000
Posts: 119
|
|
How did you put the SerObject's class definition into the deserialization client's package? Did you change the "package" declaration in SerObject.java on the client side? In that case, you have two different classes: serializer.SerObject and deserializer.SerObject. Or did you copy the class file for serializer.SerObject into the package dir for deserializer? In that case, it should be in a "serializer" directory instead to match its package hierarchy. If it's neither of those, it's something more insidious.
|
Consultant to SCJP team.<br />Co-designer of SCJD exam.<br />Co-author of "Complete Java 2 Certification Study Guide".<br />Author of "Ground-Up Java".
|
 |
Jan Groth
Ranch Hand
Joined: Feb 03, 2004
Posts: 456
|
|
Phillip, you were 100% right... I took the class definition over to the client, but put it into the wrong package.... STupid me. Thx a lot for helping, Jan
|
 |
 |
|
|
subject: Problem with Serialization / Deserialization
|
|
|