I am using the MVC ApiController to create an API for my website.
I have a base class ThinDevice that contains a subset of information for a Device. In my API I only want to serialize the properties belonging to ThinDevice but, despite me casting, and using ThinDevice as the return type when I serialize a Device it always serializes the entire object
[HttpGet]
public ThinDevice Get(string id)
{
// This returns Device
var device = this.dataService.GetDevice(id);
if (device != null)
{
// I only want to serialize properties in ThinDevice
return device as ThinDevice;
}
}
dataService.GetDevice(id). because derived types might contain values for some base class properties, may be to make the object graph complete , theserializationis considering the derived type.