Question

I am trying to implement a serializer in python which tries to do something like this.

If there is an object Foo, having a forward reference to Bar, the serializer would dump all the data in Foo, and the reference would be converted into a data dump of Bar. Things would be done recursively like this for any arbitrary depth.

But there is a problem I run into with this approach, that of circular references, what if Foo references Bar and Bar references Foo? An infinite recursion would be created then.

What are the approaches to tackling this problem.

Note: I have no control over the data I would be serializing, so I can't rule out circular references.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top