c# - How to serialize as Json an object structure with circular references? -
i have object structure this:
public class proposal { public list<proposalline> lines { get; set; } public string title { get; set; } } public class proposalline { public proposal proposal { get; set; } // <- reference parent object }
i try serialize proposal json, tells me there circular reference, correct.
unfortunately, can't touch objects, since in referenced dll project - otherwise i'd change them.
is there way serialize json , ignore circular properties?
use newtonsoft.json (which default .net json serializer) , set
jsonserializersettings settings = new jsonserializersettings { preservereferenceshandling = preservereferenceshandling.objects }; var serializer = jsonserializer.create(settings);
you can globally define variable if developing mvc applications...
Comments
Post a Comment