I have web api controller like this:
public class ParentController : ApiController
{
[HttpGet]
public IHttpActionResult GetParent()
{
//instatiating child class
var child = new Child
{
ChildProp1 = "childValue1",
ChildProp2 = "childValue2",
ParentProp1 = "parentValue1",
ParentProp2 = "parentValue2"
};
//up casting is implicit
Parent parent = child;
//returning parent as Json http request
return Ok(parent);
}
private class Child : Parent
{
public string ChildProp1 { get; set; }
public string ChildProp2 { get; set; }
}
private class Parent
{
public string ParentProp1 { get; set; }
public string ParentProp2 { get; set; }
}
}
and it works perfectly except it return Json result of both parent and child properties and What I need is only properties of parent class
Output response body:
{
"childProp1": "childValue1",
"childProp2": "childValue2",
"parentProp1": "parentValue1",
"parentProp2": "parentValue2"
}
Thanks!