How to solve dependency when deserializing object graph
===

When I deserialize an object graph by restoring all each node and edges by object itself (for object-oriented way), I found there's serious dependency problem.
For example if an object references itself, (self circular reference) it means, it expect itself in *complete original state* while it is restoring. Because it was in that state when it being serialized.

For self-referencing, it can be detected because it knows itself is being restoring. But if it needs another object, it should expect the other object in complete original state. If there's circular reference, to itself over multiple link, it becomes same.

Fundamentally, the problem is an object needs complete state of referencing objects while itself is in incomplete state. This doesn't make sense. I have thought about dividing proceed into multiple phases but it doesn't make any difference because actually the object will retain in incomplete state until all phases finish.

Can I have some advise or good solution for this problem?



PS.
I started coding this to make some replacement for Cocoa's `NSKeyedArchiver`. So I assumed encoding of object is done by the object itself. (for its internal state) So it could be different with general graph problems. But I can't exclude hidden state that can be get by the object itself...