Using Json.net, I want to deserialize a basket containing interface objects. This...
{
"Owner": "John",
"Fruit": [ <an apple object>, <a pear>, etc... ]
}
... should go into this...
class Basket
{
string Owner;
List<iFruit> Fruit; //contains instances of Apple, Pear,...
}
Interfaces cannot be instantiated, so a conversion to concrete objects is needed. I found examples using a JsonConverter to create concrete Apple and Pear instances. But the list is always created directly with a line like:
List<iFruit> fruit = JsonConvert.DeserializeObject<List<iFruit>>(json, new FruitConverter());
How do I deserialize a whole Basket, where the JsonConverter is used only for the objects in the fruit list?