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.
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
JsonSerializerOptionsoverload. 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.