You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement the JsonSerializer.IsReflectionEnabledByDefault feature switch (#83844)
* Implement the STJ.DisableDefaultReflection feature switch.
* Reinstate accidentally stripped attribute
* Address feedback.
* Address feedback.
* Add a trimming test for STJ
* Move trimming test to existing trimming tests folder.
* Add source gen serialization test case to Trimming test.
* Fix style.
* Expose the feature switch as a property on JsonSerializer -- rename feature switch to match namespace.
* Update src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
* Update src/libraries/System.Text.Json/tests/System.Text.Json.Tests/TrimmingTests/IsReflectionEnabledByDefaultFalse.cs
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
* Address feedback.
* Address feedback.
* Add entry to feature-switches.md
---------
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Copy file name to clipboardexpand all lines: docs/workflow/trimming/feature-switches.md
+1
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,7 @@ configurations but their defaults might vary as any SDK can set the defaults dif
29
29
| NullabilityInfoContextSupport | System.Reflection.NullabilityInfoContext.IsSupported | Nullable attributes can be trimmed when set to false |
30
30
| DynamicCodeSupport | System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported | Changes RuntimeFeature.IsDynamicCodeSupported to false to allow testing AOT-safe fallback code without publishing for Native AOT. |
31
31
|_AggressiveAttributeTrimming | System.AggressiveAttributeTrimming | When set to true, aggressively trims attributes to allow for the most size savings possible, even if it could result in runtime behavior changes |
32
+
| JsonSerializerIsReflectionEnabledByDefault | System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault | When set to false, disables using reflection as the default contract resolver in System.Text.Json |
32
33
33
34
Any feature-switch which defines property can be set in csproj file or
34
35
on the command line as any other MSBuild property. Those without predefined property name
Copy file name to clipboardexpand all lines: src/libraries/System.Text.Json/ref/System.Text.Json.cs
+1
Original file line number
Diff line number
Diff line change
@@ -280,6 +280,7 @@ public static partial class JsonSerializer
280
280
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
285
286
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
Copy file name to clipboardexpand all lines: src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs
+16-2
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,20 @@ public static partial class JsonSerializer
13
13
internalconststringSerializationUnreferencedCodeMessage="JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.";
14
14
internalconststringSerializationRequiresDynamicCodeMessage="JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.";
/// Constructs a new <see cref="JsonSerializerOptions"/> instance with a predefined set of options determined by the specified <see cref="JsonSerializerDefaults"/>.
148
135
/// </summary>
@@ -161,6 +148,19 @@ public JsonSerializerOptions(JsonSerializerDefaults defaults) : this()
161
148
}
162
149
}
163
150
151
+
/// <summary>Tracks the options instance to enable all instances to be enumerated.</summary>
/// Binds current <see cref="JsonSerializerOptions"/> instance with a new instance of the specified <see cref="Serialization.JsonSerializerContext"/> type.
Copy file name to clipboardexpand all lines: src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/DefaultJsonTypeInfoResolver.Helpers.cs
0 commit comments