Paolo ponzano - 174 - Feb 23, 2015

Hello,
I’ve got a “problem” when adding an Item to a Redis cache client… consider a Menu Structure where I’ve a reference to the parent… 

public class Item
{
public int ID {get;set;}
public Item Parent {get;set;}
public List<Item> Children {get;set;}

public Item()
{
Children = new List<Item>();
}
}

When I serialize this to memorycacheclient everything works fine since it saves the pointers to my objects… when serializing to redis its converted to json but it falls in a loop since I when it tries to serialize the parent item it serialize the children again, again and again… I’ve in my mind 2 solutions… the first is to keep a ParentID instead of Parent (but I will have problem to find the parent) encapsulate my menu structure in a class and try to work on deserialization hook… any suggestion?

The JSON Serializer doesn’t support serializing cyclical relationships like this. It only works in Memory Client because it doesn’t need to serialize the object.

paolo ponzano:

Was my suspect… for now I serialize a ParentID then I call a method after and update the Parent value