Forums Register Login

Object serialization and order

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
The only thing that kept the leeches off of me was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1601 times.
Similar Threads
please explain the output
Serialization Mechanism
Getting transient variable values while deserializing
static are kept away from the process of serialization
Does private instance variable participate Serialization process?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:14:55.