From e790d5e7adfe4e1af98123563ea33106eaa65f24 Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Wed, 16 Oct 2024 12:26:33 +0200 Subject: [PATCH] Fix nullability annotations in `SystemTextJsonSerializer` (#123) Fix nullability annotations in `SystemTextJsonSerializer`. --- .../Serialization/SystemTextJsonSerializer.cs | 10 ++++------ .../Serialization/TransportSerializerExtensions.cs | 4 ---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Elastic.Transport/Components/Serialization/SystemTextJsonSerializer.cs b/src/Elastic.Transport/Components/Serialization/SystemTextJsonSerializer.cs index 0a713dd..b61f1b8 100644 --- a/src/Elastic.Transport/Components/Serialization/SystemTextJsonSerializer.cs +++ b/src/Elastic.Transport/Components/Serialization/SystemTextJsonSerializer.cs @@ -3,10 +3,8 @@ // See the LICENSE file in the project root for more information using System; -using System.Collections.Generic; using System.IO; using System.Text.Json; -using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; @@ -18,8 +16,8 @@ namespace Elastic.Transport; /// public abstract class SystemTextJsonSerializer : Serializer { - private readonly JsonSerializerOptions? _options; - private readonly JsonSerializerOptions? _indentedOptions; + private readonly JsonSerializerOptions _options; + private readonly JsonSerializerOptions _indentedOptions; /// /// An abstract implementation of a transport which serializes using the Microsoft @@ -90,8 +88,8 @@ public override Task SerializeAsync(T data, Stream stream, /// Returns the for this serializer, based on the given . /// /// The serialization formatting. - /// The requested or null, if the serializer is not initialized yet. - protected internal JsonSerializerOptions? GetJsonSerializerOptions(SerializationFormatting formatting = SerializationFormatting.None) => + /// The requested . + protected internal JsonSerializerOptions GetJsonSerializerOptions(SerializationFormatting formatting = SerializationFormatting.None) => formatting is SerializationFormatting.None ? _options : _indentedOptions; private static bool TryReturnDefault(Stream? stream, out T deserialize) diff --git a/src/Elastic.Transport/Components/Serialization/TransportSerializerExtensions.cs b/src/Elastic.Transport/Components/Serialization/TransportSerializerExtensions.cs index cfc6a87..f72c9d6 100644 --- a/src/Elastic.Transport/Components/Serialization/TransportSerializerExtensions.cs +++ b/src/Elastic.Transport/Components/Serialization/TransportSerializerExtensions.cs @@ -185,8 +185,6 @@ public static string SerializeToString( return ms.Utf8String(); } - #region STJ Extensions - /// /// Extension method that writes the serialized representation of an instance of to a /// . @@ -633,6 +631,4 @@ public static void Serialize( return serializer.Deserialize(type, ms); } - - #endregion STJ Extensions }