diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs index 1cbe8cb74945b..08b6fbd518ce7 100644 --- a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs @@ -47,7 +47,7 @@ public static partial class HttpContentJsonExtensions { using (Stream contentStream = await GetContentStream(content, sourceEncoding, cancellationToken).ConfigureAwait(false)) { - return await DeserializeAsyncHelper(contentStream, type, options ?? JsonContent.s_defaultSerializerOptions, cancellationToken).ConfigureAwait(false); + return await DeserializeAsyncHelper(contentStream, type, options ?? JsonHelpers.s_defaultSerializerOptions, cancellationToken).ConfigureAwait(false); } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", @@ -63,7 +63,7 @@ public static partial class HttpContentJsonExtensions { using (Stream contentStream = await GetContentStream(content, sourceEncoding, cancellationToken).ConfigureAwait(false)) { - return await DeserializeAsyncHelper(contentStream, options ?? JsonContent.s_defaultSerializerOptions, cancellationToken).ConfigureAwait(false); + return await DeserializeAsyncHelper(contentStream, options ?? JsonHelpers.s_defaultSerializerOptions, cancellationToken).ConfigureAwait(false); } } diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonContent.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonContent.cs index 8718291e1ee33..bb9580579bce5 100644 --- a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonContent.cs +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonContent.cs @@ -16,8 +16,6 @@ namespace System.Net.Http.Json { public sealed partial class JsonContent : HttpContent { - internal static readonly JsonSerializerOptions s_defaultSerializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web); - private readonly JsonSerializerOptions? _jsonSerializerOptions; [DynamicallyAccessedMembers(JsonHelpers.SerializationMemberTypes)] public Type ObjectType { get; } @@ -43,7 +41,7 @@ public sealed partial class JsonContent : HttpContent Value = inputValue; ObjectType = inputType; Headers.ContentType = mediaType ?? JsonHelpers.GetDefaultMediaType(); - _jsonSerializerOptions = options ?? s_defaultSerializerOptions; + _jsonSerializerOptions = options ?? JsonHelpers.s_defaultSerializerOptions; } [RequiresUnreferencedCode(HttpContentJsonExtensions.SerializationUnreferencedCodeMessage)] diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonHelpers.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonHelpers.cs index 488a7941592bb..31c6a08a87295 100644 --- a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonHelpers.cs +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonHelpers.cs @@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis; using System.Net.Http.Headers; using System.Text; +using System.Text.Json; namespace System.Net.Http.Json { @@ -13,6 +14,8 @@ internal static class JsonHelpers internal const DynamicallyAccessedMemberTypes SerializationMemberTypes = DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties; internal const DynamicallyAccessedMemberTypes DeserializationMemberTypes = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties; + internal static readonly JsonSerializerOptions s_defaultSerializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web); + internal static MediaTypeHeaderValue GetDefaultMediaType() => new("application/json") { CharSet = "utf-8" }; internal static Encoding? GetEncoding(string? charset)