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 strea
I had the same problem and I also implemented the crawler thing you talked about. If somebody is still interested in it, I presented the code here: A good way to find unserializable fields in Java
This is a strange question - you're wanting to determine at runtime what you should be doing at compile time. In theory, the path to the object shouldn't matter - you need to find the objects that reference things that aren't serializable to fix your code.
That said, you could write a simple recursive tree crawler using reflection. That said, you might be able to get away with implementing your own ObjectInputStream that logs the objects coming in appropriately. I recommend taking a look at the source for more detail
Pass the flag -Dsun.io.serialization.extendedDebugInfo=true
to the JVM and it should give you exactly the information you want, when a NotSerializableException
is thrown.