Skip to content

The System.Text.Json source generator docs contain examples using JsonSerializerOptions overloads #54104

@eiriktsarpalis

Description

@eiriktsarpalis

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.

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions