Hacker News new | ask | show | jobs
by arnarbi 3355 days ago
That's not a solution as it will not restore the same object graph, it will just repeat values.

One way is to to store a table of objects (as identified by id()) encountered during serialization, indexed by the order you encounter them. If you encounter an object you have already serialized, serialize an index into that table. On deserialization, construct the same kind of table, and deserialize an index with a reference to the same object.

See e.g. AMF for an example format that does this: https://en.wikipedia.org/wiki/Action_Message_Format