Say I have the following enum:
public enum Test
{
item1 = 1,
item2 = 2,
item3 = 3
}
I add all those enums to a list using JsonConvert.SerializeObject. I then have a JSON string as follows:
["item1","item2","item3"]
I then want to Deserialize the JSON back into a list of the enums. So:
List<Test> list = JsonConvert.DeserializeObject<List<Test>>(json string);
This works, great.
However, if I remove one of the enum items after the list has been serialized I get an error.
So, my enum becomes:
public enum Test
{
item1 = 1,
item3 = 3
}
I now get an error on this line.
List<Test> list = JsonConvert.DeserializeObject<List<Test>>(json string);
The error is:
Error converting value "item2" to type 'Test'
How can I get round this?
I've tired added the following JsonSetting but this made no difference.
new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
}