Skip to content

System.Text.Json: The polymorphism attributes do not appear to work with nested objects #43575

@dcooperch

Description

@dcooperch

Type of issue

Missing information

Description

The documentation does not mention anything about nested objects.

Consider the following code:

[JsonPolymorphic]
[JsonDerivedType(typeof(Derived1), typeDiscriminator: "Derived1")]
[JsonDerivedType(typeof(Derived2), typeDiscriminator: "Derived2")]

This only appears to work at the root level model.

Current version:
System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

Page URL

https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism

Content source URL

https://github.com/dotnet/docs/blob/main/docs/standard/serialization/system-text-json/polymorphism.md

Document Version Independent Id

17511810-6572-ad88-6eaf-4f9bded720b7

Article author

@gewarren

Metadata

  • ID: 179cc49a-a37d-155e-5ecf-deca4f219a5a
  • Service: dotnet-fundamentals

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions