Java's Representation of Serialized Objects

deterministic, java, serialization

Solution

I like @Stephen C's example of Object.hashCode(). If such nondeterministic hash codes are serialized, then when we deserialize, the hash codes will be of no use. For example, if we serialize a HashMap that works based on Object.hashCode(), its deserialized version would behave differently than the original map. That is, looking up the same object would give us different results in the two maps.

Problem

I'm looking for the format that Java uses to serialize objects. The default serialization serializes the object in a binary format. In particular, I'm curious to know if two runs of a program can serialize the same object differently. What condition should an object satisfy so that the object maintains its behavior under Java's default serialization/deserialization round-trip?

Original source