Skip to content

New JSON serializer -> inheritance #13438

@ErazerBrecht

Description

@ErazerBrecht

Describe the bug

Probably it's a feature. And probably this is a question that belongs @ stackoverflow.
But I couldn't find anything.

When using AspNet Core 3.0 and not adding AddNewtonsoftJson (aka using the new JSON serializer) it 'ignores' inheritance

To Reproduce

https://github.com/ErazerBrecht/JsonTest

Most important file: https://github.com/ErazerBrecht/JsonTest/blob/master/JsonTest/Controllers/ValueController.cs

By adding 'AddNewtonsoftJson' in the Startup.cs I get my 'excepted behavior'.

Actual behaviour:

{
    transportations: [
    {
        speed: 120
    },
    {
        speed: 90
    }]
}

Expected behavior

{
    transportations: [
    {
         horsePower: 130,
         speed: 120
    },
    {
        humanCapacity: 50,
        speed: 90
    }]
}

Additional context

I checked https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions?view=netcore-3.0. But I couldn't find a setting related to 'inheritance'.
So if it's not a bug, is there somewhere documention on how to fallback to what JSON.NET used to do?

Thanks for your time
Sincerely, Brecht

Metadata

Metadata

Assignees

Labels

area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesquestion

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions