In a new .NET 5 project, I have a List<BaseClass>
as a property on a ViewModel. It has 4 properties on it. At runtime, I populate that list with 4 different derived classes, each with about 3 distinct properties of their own, in addition to the base class.
When I return this in a JsonResult
from a controller, I'm only getting the BaseClass
properties serialized in the list, when I want all the derived class properties on each respective class.
I'm not using Newtonsoft.Json
, just the built in System.Text.Json
. How can I configure it across the app to serialize the derived class properties? I'm coming up short on trying to find code examples / similar questions, that are not Newtonsoft.Json
based.
I just found these docs that tells me how to solve this problem when I'm manually doing the serialization. But I need it to work within the mvc framework