0

This Json.NET page does not explicitly mention support of IEnumerable. But of testing, it seems to work. Can I rely on this?

  • 2
    Yes. [`IEnumerable`](https://msdn.microsoft.com/en-us/library/9eekhta0%28v=vs.110%29.aspx) inherits from `IEnumerable`: `public interface IEnumerable : IEnumerable`. And from the Json.NET docs: [Serialization Guide: IEnumerable, Lists, and Arrays](http://www.newtonsoft.com/json/help/html/SerializationGuide.htm#Lists): **.NET lists (types that inherit from IEnumerable) and .NET arrays are converted to JSON arrays.** – dbc Dec 07 '15 at 23:24

1 Answers1

1

serialization is not a problem because it uses the type of the serialized object

a generic ienumerable ( IEnumerable<> ) can be deserialized because its inner type is enough for the deserializator to understand what to read, but a generic ienumerable is just an interface that need some help to be deserialized, like an explicit JsonConverter

of course i refer to serialize/deserialize to typed object and not JObject

this is a question similar to your: JSON.NET - how to deserialize collection of interface-instances?

and this blog article explain further: http://blog.greatrexpectations.com/2012/08/30/deserializing-interface-properties-using-json-net/

Community
  • 1
  • 1
Not Important
  • 762
  • 6
  • 22
  • Json.NET somehow manages to do this even without mentioning an explicit JsonConverter. Why? – Superhaxor4 Dec 07 '15 at 23:44
  • are you referring to generic or non generic ienumerable? anyway step into debugger and inspect the elements generated into your ienumerable to see what's their types – Not Important Dec 07 '15 at 23:55