I have an object which has a circular reference to another object. Given the relationship between these objects this is the right design.
To Illustrate
Machine => Customer => Machine
As is expected I run into an issue when I try to use Json to serialize a machine or customer object. What I am unsure of is how to resolve this issue as I don’t want to break the relationship between the Machine and Customer objects. What are the options for resolving this issue?
Edit
Presently I am using Json method provided by the Controller base class. So the serialization I am doing is as basic as:
Json(machineForm);
Update:
Do not try to use
NonSerializedAttribute, as theJavaScriptSerializerapparently ignores it.Instead, use the
ScriptIgnoreAttributeinSystem.Web.Script.Serialization.This way, when you toss a
Machineinto theJsonmethod, it will traverse the relationship fromMachinetoCustomerbut will not try to go back fromCustomertoMachine.The relationship is still there for your code to do as it pleases with, but the
JavaScriptSerializer(used by theJsonmethod) will ignore it.