The following example illustrates the fundamental drawback of handling Json.NET type types:
List<object> items = new List<object>() {Guid.NewGuid(),DateTime.Now}; var settings = new JsonSerializerSettings() { TypeNameHandling=TypeNameHandling.All }; var json = JsonConvert.SerializeObject<List<object>>(value,settings);
which leads to the following JSON:
{"$type":"System.Collections.Generic.List`1[[System.Object, mscorlib]], mscorlib","$values":["9d7aa4d3-a340-4cee-baa8-6af0582b8acd","2014-07-28T21:03:17.1287029-04:00"]}
As you can see, the list items have lost type information. Deserializing the same JSON will result in a list containing only strings.
This issue was previously reported by Codeplex and completely closed, stating, including type information, which would make JSON too confusing. I am surprised that we are not given a separate option to include information about the primitive type for such scenarios when there is a violation of consistency in a circle.
https://json.codeplex.com/workitem/23833
I would expect the data to return with the same type information with which it was left. Does anyone have any suggestions or workarounds to eliminate this unwanted behavior?
Thanks,
Chris
source share