Hi there,
I have a problem with servicestack as it seems it cannot handle circular references. The serializer will not throw exception if I use IgnoreDataMember on the parent, but I want to avoid it as it creates a problem when i want to retrieve order items as the parent is null.
In .net DataContract serializer, it resolves automatically, Newtonsoft.Json also resolve this circular reference automatically. I was hoping for ServiceStack to handle it in the serializer.
I have put an example below.
Many thanks
public class Order
{
public int ID { get; set; }
public List<OrderItem> Items { get; set; }
}
public class OrderItem
{
public int ID { get; set; }
//[IgnoreDataMember]
public Order Parent { get; set; }
}
class Program
{
static void Main(string[] args)
{
try
{
Order order = new Order { Items = new List<OrderItem>() };
order.Items.Add(new OrderItem { Parent = order });
order.ToJson().Print();
}
catch(Exception ex)
{
ex.Message.Print();
}
Console.ReadLine();
}
}