I'm trying to deserialize an object that basically has an array of objects where each one has a property with object type and object instance. The schema looks somewhat like this:
public class MainObject
{
public IEnumerable<Parent> Parents { get; set; }
}
public class Parent
{
public string NameOfChildObjectType { get; set; }
public Object Child { get; set; }
}
public class Child_1
{
//some props
}
public class Child_2
{
//some props but different as child 1 or 3
}
public class Child_3
{
// completely different props literally the only thing we have in common is us being children
}
And Json file
{
"id": "1",
"Name": "MainObjectName",
"Parents": [
{
"ChildName": "ChildOfType1",
"Parameters": {
"Name": "Jordan"
}
},
{
"ChildName": "ChildOfType2",
"Parameters": {
"Height": "6`2"
}
},
{
"ChildName": "ChildOfType3",
"Parameters": {
"OwnedPets": [
{
"DogName": "JJ",
"FishName": "Shrimp"
}
],
"MaxHeadRotation": "45"
}
}
]
}
So is there any way I could define a generic type that isn't shared between all the objects in the list or even deserialize them in one go? Any ideas are appreciated.