• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Serialization / Deserialization

 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic