Monday, March 10, 2008

java.io.NotSerializableException

I can't fully dedicate my time to the SCEA assignment, I am also fulltime working on projects.
Today I ran into a java.io.NotSerializableException.
The stack trace is not at all helpfull, it just says "Caused by: java.io.NotSerializableException: foo.bar.FooBar."
While I am sure that foo.bar.FooBar implements java.io.Serializable.
I checked all the class members and marked some of the members transient (log4j Logger), but still the thing is popping up.

Googling for that exception showed this blog post. As it appeared, their first attempt wasn't very useful, although the idea looked promising.
Their DebugObjectOutputStream doesn't handle private fields, and can't cope with inheritance.
These issues seem to have been resolved in the wicked code itself, but that is a bit too harsh to just get

Browsing the comments posted underneath the post showed a link to Bob Lee's blog where he tackles the same problem.
Although the output generated by his solution isn't as verbose as the other one, it does give the expected results.
This showed me that I missed out on some of the fields.
Great help. Thanks Bob.


1 comment:

Anonymous said...

I have also addressed this object not serializable exception with different examples in my own blog.
here is my blog link.
http://www.craftingjava.blogspot.in

I hope u may find this useful