I have a bunch of long json output in separate files. I need to read these files and deserialize them into the entities that json originally generated (I have access to the source objects). Each file has json output, which was generated by serializing an object of type IEnumerable<Response<MyEntity>>.
I get an exception when trying to deserialize, but I don't understand why. Here is my attempt to deserialize:
List<string> jsonOutputStrings;
List<Response<MyEntity>> apiResponses = new List<Response<MyEntity>>();
foreach (string json in jsonOutputStrings)
{
apiResponses.AddRange(JsonConvert.DeserializeObject<List<Response<MyEntity>>>(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }).ToList());
}
I also tried deserializing IEnumerable instead of a list:
apiResponses.AddRange(JsonConvert.DeserializeObject<IEnumerable<Response<MyEntity>>>(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }).ToList());
I get the following exception:
The first random exception like "Newtonsoft.Json.JsonSerializationException" occurred in Newtonsoft.Json.dll
: System.Linq.Enumerable + WhereSelectListIterator`2 [Entities.Requirement, Entities.RequirementEntity]. '$ [0].ReturnedEntity.Summaries. $ [0].Requirements. $', 1, 715.
json ( ), json, :
"Requirements":{"$id":"7","$type":"System.Linq.Enumerable+WhereSelectListIterator`2[[Entities.Requirement, Entities],[Entities.RequirementEntity, API.Entities]], System.Core","$values":[...]}
, ( , ), Requirements IEnumerable<Entities.RequirementEntity>.
, MyEntity, . ?