I was just reading in HFJ about object serialization. When we serialize an ojbect with an instance variable that is an object ref, HFJ says that the entire object graph will get serialized. But my question is: "In what order are instance variables serialized"? Does it follow the order in which they appear in the serializing class?
Thanks, leo
Maulin Vasavada
Ranch Hand
Joined: Nov 04, 2001
Posts: 1865
posted
0
Hi leo Why would that order matter to us? As far as we get the same object that we wrote its fine I guess. Thanks Maulin
It's an interesting academic question...at least, I think so. It was posted somewhere here a while back and got no answer...I can't find anything on Google and I have a few spare minutes, so let's find out:
(See bottom of post for code to HexOutputStream.) OK, so the output isn't going to be exactly legible, but:
Despite my dodgy HexOutputStream, things seem to work - the "magic number" that starts all serialisation stream (AC ED) is present at the start of the output and the serialisation format version number (00 05) is the current one for my JRE. OK, so assuming it all works the important things are 61, 62, 63 (chars 'a', 'b', 'c'). In each case, it seems they come out in that order 'a', 'b', 'c'. Conclusion: variables of the same type are serialised in alphabetical order, regardless of their scope. Question: do all variables behave like this, regardless of their type? I'd check that out, but it'd mean decoding the serialisation hex dump pretty thoroughly because other types aren't nearly as easy to find as Strings. (Maybe longs containing Long.MIN_VALUE would be easy to find?) This is hardly scientific, but it's a start. Any advances?
--Tim For reference, the HexOutputStream in its dodgy glory:
[ April 27, 2004: Message edited by: Tim West ] [ April 28, 2004: Message edited by: Tim West ]