So if I have a one-to-many relationship between two objects, I can only serialize one way, otherwise I get a cyclical error when using Json.NET.
I want to serialize the objects both ways, so I can navigate up and down the object.
Reading Json.NET's documenation, I came upon the ability to conditionally serialize a C# poco property by adding a shouldSerialize method suffixed by the property name..
Take a manager and and employee class. One manager has many employees. I want employees to backreference managers, but I only want managers to reference employees if the manager is not a property of an employee.
{
manager: {
managerId: 1,
attr1: 'blah',
employees: [
{
employeeId:1,
manager: {
manager id: 1,
attr1: 'blah',
employees: **null**
}
]
}
Is this possible to do? What's the best way to do it?