I have three classes in a domain
public class ArtistInfo
{
private Guid Id { get; set; }
public string Name { get; set; }
public string DisplayName { get; set; }
public bool IsGroup { get; set; }
public bool IsActive { get; set; }
public string Country { get; set; }
}
public class Artist : ArtistInfo
{
public DateTime Created { get; set; }
public int CreatedById { get; set; }
public DateTime Updated { get; set; }
public int UpdatedById { get; set; }
}
public class Track
{
public string Title { get; set; }
public string DisplayTitle { get; set; }
public int Year { get; set; }
public int Duration { get; set; }
public int? TrackNumber { get; set; }
//[SomeJsonAttribute]
public ArtistInfo Artist { get; set; }
}
From the ASP.NET Web API I return a generic List(of Tracks). No matter what I have tried the Web API returns the Artist property of Track as an Artist not ArtistInfo. Is there someway to limit this in the output of the API to just use ArtistInfo? I don't want to write addition "ViewModels/DTOs" to handle this situation. Can I decorate the ArtistInfo with a hint to the JSON Serializer?