Question background:
I'm receving a JSON payload from a WebApi end point, from here I am mapping the data to a C# model structure through the use of Newtonsoft. The C# classes were produced using json2csharp.com
The Issue:
The following JSON (as viewed in the JSON viewer in Visual Studio) is causing an error on the Feature property of the ItemAttributes element when attempting to be mapped to its equivalent property on the C# class:
The Feature property reads:
"Feature: Polish Release, cover may contain Polish text/markings. The disk DOES NOT have English audio and subtitles."
The following shows the generated C# ItemAttributes class from json2csharp.com with the required 'Feature' property:
public class ItemAttributes
{
public string Brand { get; set; }
public string Department { get; set; }
/* Feature string list*/
public List<string> Feature { get; set; }
public string Label { get; set; }
public string Manufacturer { get; set; }
public string NumberOfItems { get; set; }
public string PackageQuantity { get; set; }
public string ProductGroup { get; set; }
public string ProductTypeName { get; set; }
public string Publisher { get; set; }
public string Studio { get; set; }
public string Title { get; set; }
public string Binding { get; set; }
public string Color { get; set; }
public PackageDimensions PackageDimensions { get; set; }
public string Size { get; set; }
public string IsAdultProduct { get; set; }
public string MPN { get; set; }
public string PartNumber { get; set; }
public string SKU { get; set; }
}
The error that is being received:
An exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll but was not handled in user code
Additional information: Error converting value "Polish Release, cover may contain Polish text/markings. The disk DOES NOT have English audio and subtitles." to type 'System.Collections.Generic.List`1[System.String]'. Path 'Items.Item[2].ItemAttributes.Feature', line 1, position 11935.
If anyone can see why I am having issues mapping the JSON Feature property to the C# equivalent that would be great.
---------------------------EDIT---------------------------
Thanks to Ivaylos answer I can now see that the issue is a the value of the string Feature property was trying to map to a string list in the C# equivilant.
The issue I now face is sometimes the JSON returns the Feature property as a list of strings and sometimes it is a single string.
i.e ideally I need two Feature propeties, a single string:
public string Property
and a list:
public List<string> Property
Obviously I cannot set two Feature properties in the ItemAttribute class.
How can I overcome this? I have no control over how the JSON is constructed
