• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialized HashSet?  RSS feed

 
Terrence White
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I Serialize an object, should all of the fields of the object be serialized along with the object?
My object has a member whose type is HashSet.
My object is being serialized, but when I de-serialized the object, the field that is a HashSet is not populated as expected...
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All of the objects within the HashSet need to be serializable, also. Just because the set is serialized doesn't mean everything within it knows how to be serialized, also.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although, if the problem is that the HashSet contains nonserializable objects, you should get a NotSerializableException, which should make the problem obvious.
Terrence - when you say "the field that is a HashSet is not populated as expected" what do you mean? Is the field null? Does it contain an empty HashSet? A HashSet with different contents? Are the contents all different, or are some the same, or what? How exactly do you know there's something wrong?
 
Terrence White
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That fixed it.
The object that I had in the set was not Serializable.
I added that to my object, and it works.
Thanks for your help ,
Terrence
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!