I'm trying to serialize an object graph in JSON.NET in which a Galaxy contains StarSystems, a StarSystem contains Planets, a Planet contains a Colony, a Colony has an Owner, and the Galaxy also has a list of Empires, each of which has a list of explored StarSystems. So there's a circular reference between StarSystem, Planet, and Empire.
What I don't understand is the behavior I get when I serialize the object graph. Instead of throwing an error when I have the reference loop handling set to the default, and trying to serialize everything when I have it set to serialize mode, it seems to be serializing a few links in the chain, then giving up and setting arbitrary values (in my case the explored star systems) to null. Naturally this is causing crashes elsewhere in the application when it looks for star systems but finds only nulls!
Could this have something to do with the fact that some of the links in the chain are not direct references, but collections? E.g. an empire does not have one explored star system, but a list of them.
So how can I make JSON.NET serialize everything? Do I need to eliminate the circular references and just pass around ID's of objects instead of actual object references in my object model? I really don't want to do that just for serialization purposes!