I have a controller that returns a list of derived objects , a List of ICollectedEditionToGet to be precise, however when I try to serialize said objects it's only returning the properties that exist on the derived lass.
public interface ICollectedEditionToGet : IBaseCollectedEdition
{
public string? Notes { get; set; }
}
public interface IBaseCollectedEdition
{
int Id { get; set; }
string Title { get; set; }
int Volume { get; set; }
}
public abstract class BaseCollectedEditionModel : IBaseCollectedEdition
{
public int Id { get; set; }
public string Title { get; set; }
public int Volume { get; set; }
}
public class CollectedEditionToGetModel : BaseCollectedEditionModel, ICollectedEditionToGet
{
public string Notes { get; set; }
}
public async Task<IActionResult> GetCollectedEditionsToGet()
{
var CollectedEditionToGets = await Task.Run(() =>
{
return _service.TryGet();
});
return CollectedEditionToGets == null ? BadRequest() : Ok(JsonSerializer.Serialize(CollectedEditionToGets));
}
[{"Notes":"Magic Bus"},{"Notes":"The Wake"},{"Notes":"The Immaterial Gir"},{"Notes":"First Born"},{"Notes":"Omnibus"},{"Notes":"Omnibus"},{"Notes":"All Different"},{"Notes":"Molecule Man"},{"Notes":"Motherland"},{"Notes":"Gouge Away"},{"Notes":"Dirge (Already Own, wrong trade dress!)"},{"Notes":null},{"Notes":"The Counterfifth Detective"},{"Notes":"Head of the Class"}]>
So my question is why, and what am I missing?
Updated to include interfaces.