1

Closed

Poor support for IEnumerable patterns

description

One can read data from a database through an IEnumerable interface, stream through the JSON.Net serialize and optionally compress.

If the data is received over network, the receiver may optionally decompress but cannot deserialize with an IEnumerable interface, not without specialized configuration/hookup or a custom deserializer. Many would simply receive the data and deserialize as a List<>. This is fine in most cases, but when there are larger data sets to stream, this becomes unwieldy, overburdening the memory.

In cases where the data only needs to be read once, native IEnumerable support is desirable. I understand that provision of an interface does not automatically bind to a concrete object. But we don't want that. IEnumerable is special, it is like a collection, but it's read once. It requires the elements to be yielded from a function.

I have managed to implement an IEnumerable deserializer using a JsonTextReader object. An IEnumerable collection need to be located at the end of objects, as they delayed access would certainly interfere with other member access otherwise.

I believe this can be implemented in JSON.Net quite simply, but would require a fair amount of time. I will be following up this issue with a reference to my custom open source example.
Closed May 2 at 11:41 PM by JamesNK
I think this is too edge case to add to json.net - people who need it can implement it themselves or find additional code on the next to support it.

comments

merarischroeder wrote Apr 30 at 8:04 AM