In Java Serialization if a class has multiple objects (composition) then in what order the state will be retrieved?-Collection of common programming errors
If you serialise A it will be written out as:
- Start of
A abc- End of
A
Deserialisation reads the stream in the same order that serialisation wrote it. However, the serialised stream is just a sequence of octets and may have a, b and c in a different order (the fields will only ever be assigned at most once).
Further, the objects could have other references to one another. For instance, even if there is no way at runtime that Test can reference Another, deserialisation of b could include the object that is deserialised to c.