In Java, Serialization makes reading and writing objects to streams REALLY easy. For instance, the following code snippet is mostly all it takes to write objects to a stream:
ObjectOutputStream oos = ... //Initialize your output stream
Object toWrite = ... //Initialize what you want to write here
oos.writeObject(toWrite); //Writes the object to the stream
oos.flush();
This will work just fine, provided that toWrite's class implements the Serializable interface, AND that all of toWrite's non-transient member variables are also Serializable. In other words, the entire Object hierarchy you are trying to send via the toWrite reference must be Serializable. Assume that the only problem with this code is that something inside toWrite isn't Serializable.
If the hierarchy isn't completely Serializable, the call to oos.writeObject(toWrite) throws a java.io.NotSerializableException. This is all fine and good, except that the Exception doesn't give you quite everything you need to fix the problem quickly. It will tell you what class couldn't be serialized. Your stack trace might look something like this:
java.io.NotSerializableException: some.package.and.ClassIDidntExplicitlyReference
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
...
at my.package.MyClass.codeThatWroteTheOffendingObject(MyClass.java:###)
This sort of points you in the right direction, but in cases that involve deep Object hierarchies referenced by toWrite, it's not always clear where the offending class reference came from. Let's say I assign toWrite to an instance of MyClass and my instance of MyClass has a member Object reference called nonSerializableReference that has be