Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serializing HashMap

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying out the following piece of code.


The above code works fine. My question is that though i have put a non-serialized object in HashMap (new Object()), how is it that the above code does not throw java.io.NotSerializableException.

If i replace o.writeObject(m); with o.writeObject( new Object()); i get java.io.NotSerializableException.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naresh Chaurasia wrote:The above code works fine.

Really ?? Which jdk are you using ?
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Naresh,

I tried your code and its throwing Exception as expected .






Now its really a question how its working for you ?

Thanks
Javin

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the following program


I also found something else.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was making a mistake...I understood what was the problem. My constructor was never getting called, so this problem occured. Thanks any way.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is completely different. You're not making any new instance of SerializingHashMap, so your map is empty. That's why it works ! AvoidRedHerrings next time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic