The System.Text.Json source generator docs contain examples using JsonSerializerOptions overloads
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 370
Description
### Describe the issue or suggestion
The code examples in https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation include examples using `JsonSerializerOptions` overload. While these are technically correct, they result in trim warnings due to these methods defaulting to unsafe reflection. We should remove these examples and default to empahasizing use of the JsonTypeInfo overloads. We should also remove mention use of the JsonSerializerContext as they are largely obsolete and impractical to use (being non-generic).
As a footnote, we should include an explainer of why JsonSerializerOptions overloads are unsuitable in the context of Native AOT and provide a workaround that avoids false positive trimmer warnings. These would involve chaining `JsonSerializer.Serialize(value, (T)options.GetTypeInfo())` invocations which work around the issue with the built-in JsonSerializerOptions.
Contributor guide
Assessment
This issue has not been assessed yet.