File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Object serialization and order Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Object serialization and order" Watch "Object serialization and order" New topic
Author

Object serialization and order

leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
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
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


1. Have fun @ http://faq.javaranch.com/java/JavaRaq
2. Looking for simple infix2postfix conversion and postfix evaluation package? Click here
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
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 ]
 
I agree. Here's the link: jrebel
 
subject: Object serialization and order
 
Similar Threads
Serialization Mechanism
Does private instance variable participate Serialization process?
Getting transient variable values while deserializing
please explain the output
static are kept away from the process of serialization