Is it possible to deserialize an object inherited from an Abstract Class?
I have the following:
public abstract partial class Item
{
public Item() { }
public int ItemID { get; set; }
public Nullable<int> ObjectStateID { get; set; }
}
public abstract partial class Appointment : Item
{
public Appointment() { }
public string AppointmentDescription { get; set; }
}
public partial class AppointedActivity : Appointment
{
public Nullable<int> AppointedActivityID { get; set; }
}
public partial class AppointedDevice : Appointment
{
public Nullable<int> AppointedDeviceID { get; set; }
}
And I have a controller that should POST Item
s:
public Item PostItem([FromBody]Item item)
{
// item is always null here.
return item;
}
The problem I'm having is that no matter what the content of my body is, the item in the controller is always null.
Example of a JSON sent to the controller:
{
"ObjectStateID": 1,
"AppointmentDescription": "test",
"AppointedActivityID": 90902 // Valid Activity ID.
}
I'm using Entity Framework and I'm not sure what's wrong with that code.
Thanks!