Find path to offending non-Serializable member variable

前端 未结 3 2013
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 17:42

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

相关标签:
3条回答
  • 2020-12-31 18:05

    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

    0 讨论(0)
  • 2020-12-31 18:17

    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

    0 讨论(0)
  • 2020-12-31 18:19

    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.

    0 讨论(0)
提交回复
热议问题