1

Which tool can be used to trace the serialization process, the order in which fields are serialized?

I have two alternative class hierarchies. The fields are the same but in one case an object declares them directly, in the other, it is done in base class. Then, the field is not serialized. I want to know why. The extended serialization debug info does nothing.

PS! There is no SerializationExeption. Everything is working smoothely. I just want to know why field is serialized in one case but not the other.

Val
  • 1
  • 8
  • 40
  • 64
  • 3
    Is the base class also Serializable? If it isn't, it's state won't be preserved. You can make the subclass deal with serializing the parent state but its a little more involved. See the docs for Serializable: http://docs.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.html –  Aug 30 '12 at 13:42
  • Whoops. linked to old docs. Still basically the same: http://docs.oracle.com/javase/7/docs/api/index.html –  Aug 30 '12 at 13:48
  • Do you think that I hide NotSerializableException from you? – Val Aug 30 '12 at 13:49
  • You can serialize an object whose superclass does not implement Serializable without causing a NotSerializableException. Anyway, I can't reproduce the sort of error you're seeing so unless you want to post your code I don't think we can help. –  Aug 30 '12 at 14:25
  • 1
    What's the *actual* question here? Are you really looking for a tool, or just an explanation? All you need is the explanation really. Your remark about 'hiding' exceptions is irrelevant but it betrays some confusion. A non-serializable base class is simply not serialized: no exceptions are thrown. – user207421 Aug 30 '12 at 22:04
  • All the classes I speak of are serializable. I want to know how it is possible and tool would be useful as well. – Val Aug 31 '12 at 18:54

1 Answers1

0

I can only think of single-stepping the serialization code using a standard Java debugger; e.g. the one in your IDE.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Unfortunately, it is difficult to debug because http://stackoverflow.com/questions/271521/locally-declared-variables-can-not-be-inspected That is why asked the question. – Val Aug 31 '12 at 18:55