SerializeObject(collection of coleccion)

Feb 17, 2011 at 6:28 PM
Edited Mar 1, 2011 at 6:21 PM

I need to serialize\deserialize a collection of Client objects which has as property a collection of Order object, called Orders, and alone serializes the collection of objects Client without the Orders property.

public ClientCollection : IEnumerable
{}

 public OrderCollection : IEnumerable
{}

ClientCollection cliecol = new ClientCollection();
cliecol.AddClient(new Client(new DateTime(2010,8,1), 1000));
cliecol.AddClient(new Client(new DateTime(2010, 8, 31), 2000)); 

OrderCollection ordcol = new OrderCollection();
Order ord1 = new Order(1, 1000, new DateTime(2010,8,1), 10, 12.3);
Order ord2 = new Order(2, 2000, new DateTime(2010, 8, 31), 10, 15);

ordcol.AddOrder(ord1);
ordcol.AddOrder(ord2);

cliecol.GetClient(0).Orders = ordcol;
cliecol.GetClient(1).Orders = ordcol;

 string result = JsonConvert.SerializeObject(cliecol,Formatting.Indented);

 //Does not it serialize the property Orders