Let's say I wish to create a diary to keep track an infant's daily activities.
I have a parent class called DiaryEntries (fields: DateTime, PerformBy)
Then I have 2 sub-class called: FeedingEntries (fields: FoodType, Volume) DiaperingEntries (fields: PeePoop, DiaperBrand)
The records is saved in a JSON file. Sample:
{
"entries": [
{
"DateTime": "2020-11-02T21:38:53.4372208+08:00",
"PerformBy": "Jane",
"PeePoop": "Pee",
"DiaperBrand": "Pampers"
},
{
"DateTime": "2020-11-02T21:38:53.4379914+08:00",
"PerformBy": "Andy",
"FoodType": "Milk",
"Volume": "120ml"
},
{
"DateTime": "2020-11-02T21:38:53.438086+08:00",
"PerformBy": "Andy",
"PeePoop": "Poop",
"DiaperBrand": "Diaper"
}
]
}
How do I map this JSON to the 3 objects when I wish to return a list of DiaryEntries and its sub-class?
If I map the JSON to DiaryEntries object, then I only get DateTime and PerformBy. I tried to create another object which has all the fields but I think that this is wrong as I will have to add more fields to this object next time I have another entry type.