I want to parse a JSON string to a C# object that could be polymorph.
To sum it up: I don't want to instantiate the root object, but I want to instantiate the inherited object depending on the JSON input.
Here's an example of the C# objects I use:
public class Module {
public string name;
}
public class Wheel : Module {
public int amount;
public Wheel(string name, int amount) : base(name) {...}
}
public class Break : Module {
public double delay;
public Break(string name, double delay) : base(name) {...}
}
And I have this JSON string that is an array containing two JSON objects:
[{
"name":"Wheel",
"amount":4
},{
"name":"Break",
"delay":1.0
}]
I want to have this JSON-string deserialized as a C# object (list/array). Each item should be instantiated as a subclass (Wheel or Break), but since List items have to be on the same denominator, the list type has to be of type Module.