@@ -12,20 +12,32 @@ public class JsonOptions
1212 /// Gets the <see cref="System.Text.Json.JsonSerializerOptions"/> used by <see cref="SystemTextJsonInputFormatter"/> and
1313 /// <see cref="SystemTextJsonOutputFormatter"/>.
1414 /// </summary>
15- public JsonSerializerOptions JsonSerializerOptions { get ; } = new JsonSerializerOptions
15+ public JsonSerializerOptions JsonSerializerOptions { get ; }
16+
17+ public JsonOptions ( )
1618 {
17- // Limit the object graph we'll consume to a fixed depth. This prevents stackoverflow exceptions
18- // from deserialization errors that might occur from deeply nested objects.
19- // This value is the same for model binding and Json.Net's serialization.
20- MaxDepth = MvcOptions . DefaultMaxModelBindingRecursionDepth ,
19+ JsonSerializerOptions = new JsonSerializerOptions
20+ {
21+ // Limit the object graph we'll consume to a fixed depth. This prevents stackoverflow exceptions
22+ // from deserialization errors that might occur from deeply nested objects.
23+ // This value is the same for model binding and Json.Net's serialization.
24+ MaxDepth = MvcOptions . DefaultMaxModelBindingRecursionDepth ,
25+
26+ // We're using case-insensitive because there's a TON of code that there that does uses JSON.NET's default
27+ // settings (preserve case) - including the WebAPIClient. This worked when we were using JSON.NET + camel casing
28+ // because JSON.NET is case-insensitive by default.
29+ PropertyNameCaseInsensitive = true ,
2130
22- // We're using case-insensitive because there's a TON of code that there that does uses JSON.NET's default
23- // settings (preserve case) - including the WebAPIClient. This worked when we were using JSON.NET + camel casing
24- // because JSON.NET is case-insensitive by default.
25- PropertyNameCaseInsensitive = true ,
31+ // Use camel casing for properties
32+ PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
33+ } ;
34+ }
2635
27- // Use camel casing for properties
28- PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
29- } ;
36+ // Initialize JsonOptions with already configured serializer options.
37+ // Note that these options will be publically accessible.
38+ internal JsonOptions ( JsonSerializerOptions serializerOptions )
39+ {
40+ JsonSerializerOptions = serializerOptions ;
41+ }
3042 }
3143}
0 commit comments