This project has moved and is read-only. For the latest updates, please go here.

Deserialize to custom collection

Feb 1, 2012 at 11:59 AM


Thanks for a great library!  I have a couple of questions I haven't been able to answer from the docs/source so far, hopefully I can get some pointers.

First, I have some JSON which is an array of objects.  I can deserialize this just fine using 


I now want to deserialize this array into a custom collection type that I have created (I want to filter the array as I'm reading it in as it's very long).  I created a class CustomCollection that implements ICollection<myObj>, but when I call JsonConvert.DeserializeObject<CustomCollection> with the same input I just get null back - it appears that the type is not being created at all.

If I use JsonConvert.PopulateObject(instance_of_my_custom_collection) then it all works correctly.

Secondly, is there a way to deserialize directly from a stream, rather than reading the stream into a string and then deserializing?  I haven't been able to find an example or overload so far...

Thanks for any help anyone can offer!