Derived type's properties missing in JSON response from ASP.NET Core API

前端 未结 6 1864
无人共我
无人共我 2021-02-13 02:51

The JSON response from my ASP.NET Core 3.1 API controller is missing properties. This happens when a property uses a derived type; any properties defined in the derived type but

6条回答
  •  难免孤独
    2021-02-13 03:16

    While the other answers are good and solves the problem, if all you want is the general behavior to be like pre netcore3, you can use the Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package and in Startup.cs do:

    services.AddControllers().AddNewtonsoftJson()
    

    More info here. This way, you don't need to create any extra json-converters.

提交回复
热议问题