This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem with Serialization / Deserialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with Serialization / Deserialization" Watch "Problem with Serialization / Deserialization" New topic
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: 24168
    
  30

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Serialization / Deserialization
 
Similar Threads
Why are transient static variables allowed?
java.io.StreamCorruptedException: invalid stream header:i understand its a thread issue not sure fix
Writing/Reading multiple objects of same class using Serialization?
ObjectInputStream.available() returning 0, but readObject returns the object
Serialization in java