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

前端 未结 6 1875
无人共我
无人共我 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:21

    I was also struggling with this in a .NET Core 3.1 API, where I wanted the result to include $type attribute.

    As suggested, install the correct package and then 'AddNewtonsoftJson'.

    I wanted the $type field to be added to show the derived type handling, to get that

    services.AddControllers().AddNewtonsoftJson(options => 
    { 
        options.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All;
    });
    

提交回复
热议问题