Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Serialization / Deserialization

 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic