Serialization a class which inherited from Collection

Jan 12, 2010 at 2:32 PM

I'd like to serialization a class inherited from Collection and save both the items and the ActivePageIndex, if I use JsonArrayAttribute, I only got the items saved, if I use JsonObjectAttribute, I only got string "(Collection)".

Is there anyway to do it?

public class Pages : ObservableCollection<String>
//other properties...
public int ActivePageIndex;
//other properties...

Jan 12, 2010 at 9:05 PM

You can't have both. A collection is serialized as an array so there would be nowhere to put the property values because there are no properties on an array.

Jan 12, 2010 at 9:28 PM

but it's strange that serialization got "(Collection)" when using [JsonObject(MemberSerialization.OptIn)].

why not serialize it as a normal class when [JsonObject(MemberSerialization.OptIn)] ?

Jan 12, 2010 at 10:39 PM

Hmmm I suspect it might be caused by a TypeConverter associated with ObservableCollection<T>