I have a simple query and I want to map it into my DTO.
{
"list": [
{ "propA": "A1" },
{ "propA": "A2" },
{ "propB": "B1" },
...
]
}
I tried something like this, but of course the .net couldn't figure out which class should use for map into:
public abstract class BaseClass {
}
public class ClassA : BaseClass {
public string PropA { get; set; }
}
public class ClassB : BaseClass {
public string PropB { get; set; }
}
public class MyDto {
public List<BaseClass> List { get; set; }
}
Finally my controller class method for the sake of completeness:
[HttpPost]
public Task<IActionResult> Create(MyDto obj) {
...
}
So the question is, how can I map my JSON request body into my object with PropA
and PropB
properties?