dotnet / dotnet/docs

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

Open
#43,575 0 comments 0 reactions 0 assignees View on GitHub
:watch: Not Triaged dotnet-fundamentals/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

### 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](https://github.com/dotnet/docs/issues?q=is%3Aissue+is%3Aopen+17511810-6572-ad88-6eaf-4f9bded720b7)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.