From d2efdd6367b9531a905aaeee59bd67be43c3b916 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Tue, 16 Jul 2024 12:05:59 -0700 Subject: [PATCH 01/21] Code changes to make STJ serializer public for preview. --- .../src/Serializer/CosmosSystemTextJsonSerializer.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs index ac5550b128..938d634f1c 100644 --- a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs +++ b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs @@ -13,7 +13,12 @@ namespace Microsoft.Azure.Cosmos /// /// This class provides a default implementation of System.Text.Json Cosmos Linq Serializer. /// - internal class CosmosSystemTextJsonSerializer : CosmosLinqSerializer +#if PREVIEW + public +#else + internal +#endif + class CosmosSystemTextJsonSerializer : CosmosLinqSerializer { /// /// A read-only instance of . @@ -25,7 +30,7 @@ internal class CosmosSystemTextJsonSerializer : CosmosLinqSerializer /// with the default values for the Cosmos SDK /// /// An instance of containing the json serialization options. - internal CosmosSystemTextJsonSerializer( + public CosmosSystemTextJsonSerializer( JsonSerializerOptions jsonSerializerOptions) { this.jsonSerializerOptions = jsonSerializerOptions; From bfdb850b6d3cbcbb7771156aa3b8a0d94a316b14 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Tue, 16 Jul 2024 13:03:36 -0700 Subject: [PATCH 02/21] Code changes to make STJ serializer public for GA. --- .../CosmosSystemTextJsonSerializer.cs | 7 +- .../Contracts/DotNetSDKAPI.json | 110 +++++++++++++++++- 2 files changed, 109 insertions(+), 8 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs index 938d634f1c..3575782665 100644 --- a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs +++ b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs @@ -13,12 +13,7 @@ namespace Microsoft.Azure.Cosmos /// /// This class provides a default implementation of System.Text.Json Cosmos Linq Serializer. /// -#if PREVIEW - public -#else - internal -#endif - class CosmosSystemTextJsonSerializer : CosmosLinqSerializer + public class CosmosSystemTextJsonSerializer : CosmosLinqSerializer { /// /// A read-only instance of . diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 89074f0fef..9a2189520f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -3407,7 +3407,34 @@ "NestedTypes": {} }, "Microsoft.Azure.Cosmos.CosmosLinqSerializer;Microsoft.Azure.Cosmos.CosmosSerializer;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, + "Subclasses": { + "Microsoft.Azure.Cosmos.CosmosSystemTextJsonSerializer;Microsoft.Azure.Cosmos.CosmosLinqSerializer;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.IO.Stream ToStream[T](T)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.IO.Stream ToStream[T](T);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" + }, + "System.String SerializeMemberName(System.Reflection.MemberInfo)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "T FromStream[T](System.IO.Stream)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "T FromStream[T](System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(System.Text.Json.JsonSerializerOptions)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(System.Text.Json.JsonSerializerOptions), Void .ctor(System.Text.Json.JsonSerializerOptions)]" + } + }, + "NestedTypes": {} + } + }, "Members": { "System.String SerializeMemberName(System.Reflection.MemberInfo)": { "Type": "Method", @@ -3658,7 +3685,34 @@ "Microsoft.Azure.Cosmos.CosmosSerializer;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": { "Microsoft.Azure.Cosmos.CosmosLinqSerializer;Microsoft.Azure.Cosmos.CosmosSerializer;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, + "Subclasses": { + "Microsoft.Azure.Cosmos.CosmosSystemTextJsonSerializer;Microsoft.Azure.Cosmos.CosmosLinqSerializer;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.IO.Stream ToStream[T](T)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.IO.Stream ToStream[T](T);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" + }, + "System.String SerializeMemberName(System.Reflection.MemberInfo)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "T FromStream[T](System.IO.Stream)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "T FromStream[T](System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(System.Text.Json.JsonSerializerOptions)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(System.Text.Json.JsonSerializerOptions), Void .ctor(System.Text.Json.JsonSerializerOptions)]" + } + }, + "NestedTypes": {} + } + }, "Members": { "System.String SerializeMemberName(System.Reflection.MemberInfo)": { "Type": "Method", @@ -3667,6 +3721,32 @@ } }, "NestedTypes": {} + }, + "Microsoft.Azure.Cosmos.CosmosSystemTextJsonSerializer;Microsoft.Azure.Cosmos.CosmosLinqSerializer;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.IO.Stream ToStream[T](T)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.IO.Stream ToStream[T](T);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" + }, + "System.String SerializeMemberName(System.Reflection.MemberInfo)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "T FromStream[T](System.IO.Stream)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "T FromStream[T](System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(System.Text.Json.JsonSerializerOptions)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(System.Text.Json.JsonSerializerOptions), Void .ctor(System.Text.Json.JsonSerializerOptions)]" + } + }, + "NestedTypes": {} } }, "Members": { @@ -3683,6 +3763,32 @@ }, "NestedTypes": {} }, + "Microsoft.Azure.Cosmos.CosmosSystemTextJsonSerializer;Microsoft.Azure.Cosmos.CosmosLinqSerializer;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.IO.Stream ToStream[T](T)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.IO.Stream ToStream[T](T);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" + }, + "System.String SerializeMemberName(System.Reflection.MemberInfo)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "T FromStream[T](System.IO.Stream)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "T FromStream[T](System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor(System.Text.Json.JsonSerializerOptions)": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(System.Text.Json.JsonSerializerOptions), Void .ctor(System.Text.Json.JsonSerializerOptions)]" + } + }, + "NestedTypes": {} + }, "Microsoft.Azure.Cosmos.CosmosThresholdOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { From 93a0f9ca8af95fd60cc79207f60e15ec121e0644 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Thu, 18 Jul 2024 17:18:03 -0700 Subject: [PATCH 03/21] Code changes to hide STJ serializer implementation behind a boolean flag. --- .../src/CosmosClientOptions.cs | 21 ++- .../src/Fluent/CosmosClientBuilder.cs | 10 ++ .../CosmosSystemTextJsonSerializer.cs | 4 +- ...inqAggregateCustomSerializationBaseline.cs | 5 +- ...TranslationWithCustomSerializerBaseline.cs | 2 +- .../Contracts/DotNetSDKAPI.json | 129 +++--------------- .../CosmosClientOptionsUnitTests.cs | 13 ++ 7 files changed, 67 insertions(+), 117 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 6bfc65a005..336887a7a8 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -392,6 +392,15 @@ public ConnectionMode ConnectionMode /// /// public bool? EnableContentResponseOnWrite { get; set; } + + /// + /// Gets or sets the boolean flag to indicate if the default STJ serializer needed to be + /// used for JSON serialization. + /// + /// + /// The default value is false + /// + public bool UseSystemTextJsonForSerialization { get; set; } = false; /// /// Gets or sets the advanced replica selection flag. The advanced replica selection logic keeps track of the replica connection @@ -583,6 +592,11 @@ public CosmosSerializer Serializer throw new ArgumentException( $"{nameof(this.Serializer)} is not compatible with {nameof(this.SerializerOptions)}. Only one can be set. "); } + + if (this.UseSystemTextJsonForSerialization) + { + throw new ArgumentException($"Cannot set a custom {nameof(this.Serializer)} when {nameof(this.UseSystemTextJsonForSerialization)} is enabled. Either specify a custom or set {nameof(this.UseSystemTextJsonForSerialization)} to the default STJ serializer."); + } this.serializerInternal = value; } @@ -833,8 +847,11 @@ internal Func GetServerCerti internal void SetSerializerIfNotConfigured(CosmosSerializer serializer) { if (this.serializerInternal == null) - { - this.serializerInternal = serializer ?? throw new ArgumentNullException(nameof(serializer)); + { + this.serializerInternal = this.UseSystemTextJsonForSerialization + ? new CosmosSystemTextJsonSerializer( + new System.Text.Json.JsonSerializerOptions()) + : serializer ?? throw new ArgumentNullException(nameof(serializer)); } } diff --git a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs index 43232aa422..96dadcadf8 100644 --- a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs +++ b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs @@ -726,6 +726,16 @@ internal CosmosClientBuilder WithPartitionLevelFailoverEnabled() this.clientOptions.EnablePartitionLevelFailover = true; return this; } + + /// + /// Enables the usage of as the default + /// serializer. + /// + internal CosmosClientBuilder WithSystemTextJsonSerializerEnabled() + { + this.clientOptions.UseSystemTextJsonForSerialization = true; + return this; + } /// /// Enables SDK to inject fault. Used for testing applications. diff --git a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs index 3575782665..ac5550b128 100644 --- a/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs +++ b/Microsoft.Azure.Cosmos/src/Serializer/CosmosSystemTextJsonSerializer.cs @@ -13,7 +13,7 @@ namespace Microsoft.Azure.Cosmos /// /// This class provides a default implementation of System.Text.Json Cosmos Linq Serializer. /// - public class CosmosSystemTextJsonSerializer : CosmosLinqSerializer + internal class CosmosSystemTextJsonSerializer : CosmosLinqSerializer { /// /// A read-only instance of . @@ -25,7 +25,7 @@ public class CosmosSystemTextJsonSerializer : CosmosLinqSerializer /// with the default values for the Cosmos SDK /// /// An instance of containing the json serialization options. - public CosmosSystemTextJsonSerializer( + internal CosmosSystemTextJsonSerializer( JsonSerializerOptions jsonSerializerOptions) { this.jsonSerializerOptions = jsonSerializerOptions; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs index ac686b31e1..caa79fbd44 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs @@ -29,7 +29,6 @@ public class LinqAggregateCustomSerializationBaseline : BaselineTests cosmosClientBuilder.WithCustomSerializer(stjCosmosSerializer)); + => cosmosClientBuilder.WithSystemTextJsonSerializerEnabled()); // Set a callback to get the handle of the last executed query to do the verification // This is neede because aggregate queries return type is a scalar so it can't be used diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs index 1224f48074..8a4bd7e254 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs @@ -57,7 +57,7 @@ public async static Task Initialize(TestContext textContext) TestDb = await CosmosClient.CreateDatabaseAsync(dbName); CosmosDefaultSTJClient = TestCommon.CreateCosmosClient((cosmosClientBuilder) - => cosmosClientBuilder.WithCustomSerializer(new CosmosSystemTextJsonSerializer(new JsonSerializerOptions()))); + => cosmosClientBuilder.WithSystemTextJsonSerializerEnabled()); string dbNameSTJ = $"{nameof(LinqTranslationBaselineTests)}-{Guid.NewGuid():N}"; TestDbSTJDefault = await CosmosDefaultSTJClient.CreateDatabaseAsync(dbNameSTJ); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 9a2189520f..c428e1046d 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -2711,11 +2711,23 @@ ], "MethodInfo": "Boolean get_LimitToEndpoint();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "Boolean get_UseSystemTextJsonForSerialization()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Boolean get_UseSystemTextJsonForSerialization();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "Boolean LimitToEndpoint": { "Type": "Property", "Attributes": [], "MethodInfo": "Boolean LimitToEndpoint;CanRead:True;CanWrite:True;Boolean get_LimitToEndpoint();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_LimitToEndpoint(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "Boolean UseSystemTextJsonForSerialization": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Boolean UseSystemTextJsonForSerialization;CanRead:True;CanWrite:True;Boolean get_UseSystemTextJsonForSerialization();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_UseSystemTextJsonForSerialization(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "Int32 GatewayModeMaxConnectionLimit": { "Type": "Property", "Attributes": [], @@ -3165,6 +3177,13 @@ ], "MethodInfo": "Void set_TokenCredentialBackgroundRefreshInterval(System.Nullable`1[System.TimeSpan]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "Void set_UseSystemTextJsonForSerialization(Boolean)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Void set_UseSystemTextJsonForSerialization(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "Void set_WebProxy(System.Net.IWebProxy)": { "Type": "Method", "Attributes": [], @@ -3407,34 +3426,7 @@ "NestedTypes": {} }, "Microsoft.Azure.Cosmos.CosmosLinqSerializer;Microsoft.Azure.Cosmos.CosmosSerializer;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": { - "Microsoft.Azure.Cosmos.CosmosSystemTextJsonSerializer;Microsoft.Azure.Cosmos.CosmosLinqSerializer;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, - "Members": { - "System.IO.Stream ToStream[T](T)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.IO.Stream ToStream[T](T);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" - }, - "System.String SerializeMemberName(System.Reflection.MemberInfo)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "T FromStream[T](System.IO.Stream)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "T FromStream[T](System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(System.Text.Json.JsonSerializerOptions)": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(System.Text.Json.JsonSerializerOptions), Void .ctor(System.Text.Json.JsonSerializerOptions)]" - } - }, - "NestedTypes": {} - } - }, + "Subclasses": {}, "Members": { "System.String SerializeMemberName(System.Reflection.MemberInfo)": { "Type": "Method", @@ -3685,65 +3677,12 @@ "Microsoft.Azure.Cosmos.CosmosSerializer;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": { "Microsoft.Azure.Cosmos.CosmosLinqSerializer;Microsoft.Azure.Cosmos.CosmosSerializer;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": { - "Microsoft.Azure.Cosmos.CosmosSystemTextJsonSerializer;Microsoft.Azure.Cosmos.CosmosLinqSerializer;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, - "Members": { - "System.IO.Stream ToStream[T](T)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.IO.Stream ToStream[T](T);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" - }, - "System.String SerializeMemberName(System.Reflection.MemberInfo)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "T FromStream[T](System.IO.Stream)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "T FromStream[T](System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(System.Text.Json.JsonSerializerOptions)": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(System.Text.Json.JsonSerializerOptions), Void .ctor(System.Text.Json.JsonSerializerOptions)]" - } - }, - "NestedTypes": {} - } - }, - "Members": { - "System.String SerializeMemberName(System.Reflection.MemberInfo)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - } - }, - "NestedTypes": {} - }, - "Microsoft.Azure.Cosmos.CosmosSystemTextJsonSerializer;Microsoft.Azure.Cosmos.CosmosLinqSerializer;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { - "System.IO.Stream ToStream[T](T)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.IO.Stream ToStream[T](T);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" - }, "System.String SerializeMemberName(System.Reflection.MemberInfo)": { "Type": "Method", "Attributes": [], - "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "T FromStream[T](System.IO.Stream)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "T FromStream[T](System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(System.Text.Json.JsonSerializerOptions)": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(System.Text.Json.JsonSerializerOptions), Void .ctor(System.Text.Json.JsonSerializerOptions)]" + "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} @@ -3763,32 +3702,6 @@ }, "NestedTypes": {} }, - "Microsoft.Azure.Cosmos.CosmosSystemTextJsonSerializer;Microsoft.Azure.Cosmos.CosmosLinqSerializer;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { - "Subclasses": {}, - "Members": { - "System.IO.Stream ToStream[T](T)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.IO.Stream ToStream[T](T);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" - }, - "System.String SerializeMemberName(System.Reflection.MemberInfo)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.String SerializeMemberName(System.Reflection.MemberInfo);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "T FromStream[T](System.IO.Stream)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "T FromStream[T](System.IO.Stream);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" - }, - "Void .ctor(System.Text.Json.JsonSerializerOptions)": { - "Type": "Constructor", - "Attributes": [], - "MethodInfo": "[Void .ctor(System.Text.Json.JsonSerializerOptions), Void .ctor(System.Text.Json.JsonSerializerOptions)]" - } - }, - "NestedTypes": {} - }, "Microsoft.Azure.Cosmos.CosmosThresholdOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs index 293c3b14ab..9fdf6061c9 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs @@ -501,6 +501,19 @@ public void ThrowOnCustomSerializerWithSerializerOptions() options.Serializer = new CosmosJsonDotNetSerializer(); } + + [TestMethod] + [ExpectedException(typeof(ArgumentException))] + public void ThrowOnCustomSerializerWithSTJSerializerEnabled() + { + CosmosClientOptions options = new CosmosClientOptions() + { + Serializer = new CosmosJsonDotNetSerializer() + }; + + options.SerializerOptions = new CosmosSerializationOptions(); + options.UseSystemTextJsonForSerialization = true; + } [TestMethod] [ExpectedException(typeof(ArgumentNullException))] From c1ee171c22d13be392261ff5a243f630cccdb669 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Fri, 19 Jul 2024 00:18:10 -0700 Subject: [PATCH 04/21] Code changes to fix tests. --- ...stAggregateQueriesWithCustomSerializer.xml | 12 +-- ...mberInitializerDotNetDefaultSerializer.xml | 92 +++++++++---------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqAggregateCustomSerializationBaseline.TestAggregateQueriesWithCustomSerializer.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqAggregateCustomSerializationBaseline.TestAggregateQueriesWithCustomSerializer.xml index 10b5e673b6..7c329aee11 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqAggregateCustomSerializationBaseline.TestAggregateQueriesWithCustomSerializer.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqAggregateCustomSerializationBaseline.TestAggregateQueriesWithCustomSerializer.xml @@ -130,7 +130,7 @@ FROM root]]> @@ -141,7 +141,7 @@ FROM root]]> @@ -154,7 +154,7 @@ FROM root]]> @@ -167,11 +167,11 @@ WHERE ((m0 % 3) = 0)]]> - + @@ -181,7 +181,7 @@ FROM ( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDotNetDefaultSerializer.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDotNetDefaultSerializer.xml index ca941f5bd0..a299b65db2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDotNetDefaultSerializer.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDotNetDefaultSerializer.xml @@ -8,11 +8,11 @@ +WHERE (root["NumericField"] = 1)]]> +WHERE (root = {"NumericField": 1, "StringField": "1", "IgnoreField": null, "id": null, "Pk": null, "DateTimeField": null, "DataTypeField": null})]]> @@ -44,12 +44,12 @@ WHERE (root = {"NumberValueDotNet": 1, "StringValueDotNet": "1", "id": null, "Pk 1) ? {"NumberValueDotNet": 1, "StringValueDotNet": "1", "id": null, "Pk": null, "DateTimeFieldDotNet": null, "DataTypeField": null} : {"NumberValueDotNet": 1, "StringValueDotNet": "1", "id": null, "Pk": null, "DateTimeFieldDotNet": null, "DataTypeField": null}) +SELECT VALUE ((root["NumericField"] > 1) ? {"NumericField": 1, "StringField": "1", "IgnoreField": null, "id": null, "Pk": null, "DateTimeField": null, "DataTypeField": null} : {"NumericField": 1, "StringField": "1", "IgnoreField": null, "id": null, "Pk": null, "DateTimeField": null, "DataTypeField": null}) FROM root]]> +WHERE (root = {"NumericField": root["NumericField"], "StringField": root["StringField"]})]]> @@ -106,11 +106,11 @@ WHERE (root = {"NumberValueDotNet": root["NumberValueDotNet"], "StringValueDotNe +ORDER BY root["NumericField"] ASC]]> 1) ? "true" : "false") +SELECT VALUE ((root["NumericField"] > 1) ? "true" : "false") FROM root]]> +WHERE (root["DateTimeField"] != null)]]> @@ -169,9 +169,9 @@ SELECT VALUE root FROM root WHERE (root["DataTypeField"] != null)]]> @@ -185,11 +185,11 @@ WHERE (root["DataTypeField"] != null)]]> +WHERE (root["DateTimeField"] = "1970-01-01T00:00:00Z")]]> @@ -205,9 +205,9 @@ SELECT VALUE root FROM root WHERE (root["DataTypeField"] = 2)]]> @@ -221,11 +221,11 @@ WHERE (root["DataTypeField"] = 2)]]> +WHERE (root["StringField"] != null)]]> Date: Fri, 19 Jul 2024 09:21:15 -0700 Subject: [PATCH 05/21] Revert "Code changes to fix tests." This reverts commit c1ee171c22d13be392261ff5a243f630cccdb669. --- ...stAggregateQueriesWithCustomSerializer.xml | 12 +-- ...mberInitializerDotNetDefaultSerializer.xml | 92 +++++++++---------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqAggregateCustomSerializationBaseline.TestAggregateQueriesWithCustomSerializer.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqAggregateCustomSerializationBaseline.TestAggregateQueriesWithCustomSerializer.xml index 7c329aee11..10b5e673b6 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqAggregateCustomSerializationBaseline.TestAggregateQueriesWithCustomSerializer.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqAggregateCustomSerializationBaseline.TestAggregateQueriesWithCustomSerializer.xml @@ -130,7 +130,7 @@ FROM root]]> @@ -141,7 +141,7 @@ FROM root]]> @@ -154,7 +154,7 @@ FROM root]]> @@ -167,11 +167,11 @@ WHERE ((m0 % 3) = 0)]]> - + @@ -181,7 +181,7 @@ FROM ( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDotNetDefaultSerializer.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDotNetDefaultSerializer.xml index a299b65db2..ca941f5bd0 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDotNetDefaultSerializer.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationWithCustomSerializerBaseline.TestMemberInitializerDotNetDefaultSerializer.xml @@ -8,11 +8,11 @@ +WHERE (root["NumberValueDotNet"] = 1)]]> +WHERE (root = {"NumberValueDotNet": 1, "StringValueDotNet": "1", "id": null, "Pk": null, "DateTimeFieldDotNet": null, "DataTypeField": null})]]> @@ -44,12 +44,12 @@ WHERE (root = {"NumericField": 1, "StringField": "1", "IgnoreField": null, "id": 1) ? {"NumericField": 1, "StringField": "1", "IgnoreField": null, "id": null, "Pk": null, "DateTimeField": null, "DataTypeField": null} : {"NumericField": 1, "StringField": "1", "IgnoreField": null, "id": null, "Pk": null, "DateTimeField": null, "DataTypeField": null}) +SELECT VALUE ((root["NumberValueDotNet"] > 1) ? {"NumberValueDotNet": 1, "StringValueDotNet": "1", "id": null, "Pk": null, "DateTimeFieldDotNet": null, "DataTypeField": null} : {"NumberValueDotNet": 1, "StringValueDotNet": "1", "id": null, "Pk": null, "DateTimeFieldDotNet": null, "DataTypeField": null}) FROM root]]> +WHERE (root = {"NumberValueDotNet": root["NumberValueDotNet"], "StringValueDotNet": root["StringValueDotNet"]})]]> @@ -106,11 +106,11 @@ WHERE (root = {"NumericField": root["NumericField"], "StringField": root["String +ORDER BY root["NumberValueDotNet"] ASC]]> 1) ? "true" : "false") +SELECT VALUE ((root["NumberValueDotNet"] > 1) ? "true" : "false") FROM root]]> +WHERE (root["DateTimeFieldDotNet"] != null)]]> @@ -169,9 +169,9 @@ SELECT VALUE root FROM root WHERE (root["DataTypeField"] != null)]]> @@ -185,11 +185,11 @@ WHERE (root["DataTypeField"] != null)]]> +WHERE (root["DateTimeFieldDotNet"] = "1970-01-01T00:00:00Z")]]> @@ -205,9 +205,9 @@ SELECT VALUE root FROM root WHERE (root["DataTypeField"] = 2)]]> @@ -221,11 +221,11 @@ WHERE (root["DataTypeField"] = 2)]]> +WHERE (root["StringValueDotNet"] != null)]]> Date: Fri, 19 Jul 2024 10:18:09 -0700 Subject: [PATCH 06/21] Code changes to fix baseline test. --- .../LinqTranslationWithCustomSerializerBaseline.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs index 8a4bd7e254..a54612398f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs @@ -57,7 +57,8 @@ public async static Task Initialize(TestContext textContext) TestDb = await CosmosClient.CreateDatabaseAsync(dbName); CosmosDefaultSTJClient = TestCommon.CreateCosmosClient((cosmosClientBuilder) - => cosmosClientBuilder.WithSystemTextJsonSerializerEnabled()); + => cosmosClientBuilder.WithSystemTextJsonSerializerEnabled(), + useCustomSeralizer: false); string dbNameSTJ = $"{nameof(LinqTranslationBaselineTests)}-{Guid.NewGuid():N}"; TestDbSTJDefault = await CosmosDefaultSTJClient.CreateDatabaseAsync(dbNameSTJ); From c6a172c33b1c73371827aa09e48a3f333b2bff05 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Fri, 19 Jul 2024 12:15:04 -0700 Subject: [PATCH 07/21] Code changes to fix root cause. --- Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs | 10 +--------- .../src/Resource/ClientContextCore.cs | 6 ++++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 336887a7a8..67eec1dc41 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -593,11 +593,6 @@ public CosmosSerializer Serializer $"{nameof(this.Serializer)} is not compatible with {nameof(this.SerializerOptions)}. Only one can be set. "); } - if (this.UseSystemTextJsonForSerialization) - { - throw new ArgumentException($"Cannot set a custom {nameof(this.Serializer)} when {nameof(this.UseSystemTextJsonForSerialization)} is enabled. Either specify a custom or set {nameof(this.UseSystemTextJsonForSerialization)} to the default STJ serializer."); - } - this.serializerInternal = value; } } @@ -848,10 +843,7 @@ internal void SetSerializerIfNotConfigured(CosmosSerializer serializer) { if (this.serializerInternal == null) { - this.serializerInternal = this.UseSystemTextJsonForSerialization - ? new CosmosSystemTextJsonSerializer( - new System.Text.Json.JsonSerializerOptions()) - : serializer ?? throw new ArgumentNullException(nameof(serializer)); + this.serializerInternal = serializer ?? throw new ArgumentNullException(nameof(serializer)); } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs index a8cc0d59dc..36238a6d74 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs @@ -128,6 +128,12 @@ internal static CosmosClientContext Create( requestInvokerHandler = clientPipelineBuilder.Build(); } + if (clientOptions.UseSystemTextJsonForSerialization) + { + clientOptions.Serializer = new CosmosSystemTextJsonSerializer( + new System.Text.Json.JsonSerializerOptions()); + } + CosmosSerializerCore serializerCore = CosmosSerializerCore.Create( clientOptions.Serializer, clientOptions.SerializerOptions); From 9015d6c546bc4c37e5651e5b05a3b30f7145385e Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Fri, 19 Jul 2024 12:48:38 -0700 Subject: [PATCH 08/21] Code changes to update tests. --- .../src/CosmosClientOptions.cs | 10 ++++-- .../CosmosClientOptionsUnitTests.cs | 33 +++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 67eec1dc41..24479e9e60 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -396,7 +396,11 @@ public ConnectionMode ConnectionMode /// /// Gets or sets the boolean flag to indicate if the default STJ serializer needed to be /// used for JSON serialization. - /// + /// + /// + /// Note that, if this flag is set to true, then any custom seriliazer provided will be disregarded and overridden with the + /// default STJ serializer . + /// /// /// The default value is false /// @@ -592,7 +596,7 @@ public CosmosSerializer Serializer throw new ArgumentException( $"{nameof(this.Serializer)} is not compatible with {nameof(this.SerializerOptions)}. Only one can be set. "); } - + this.serializerInternal = value; } } @@ -842,7 +846,7 @@ internal Func GetServerCerti internal void SetSerializerIfNotConfigured(CosmosSerializer serializer) { if (this.serializerInternal == null) - { + { this.serializerInternal = serializer ?? throw new ArgumentNullException(nameof(serializer)); } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs index 9fdf6061c9..f060fd2698 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs @@ -13,6 +13,7 @@ namespace Microsoft.Azure.Cosmos.Tests using System.Net.Security; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; + using System.Text; using global::Azure.Core; using Microsoft.Azure.Cosmos.Fluent; using Microsoft.Azure.Documents; @@ -476,43 +477,49 @@ public void UserAgentContainsEnvironmentInformation() Assert.AreEqual(userAgentSuffix, connectionPolicy.UserAgentSuffix); Assert.IsTrue(connectionPolicy.UserAgentContainer.UserAgent.StartsWith(expectedValue)); Assert.IsTrue(connectionPolicy.UserAgentContainer.UserAgent.EndsWith(userAgentSuffix)); - } - + } + [TestMethod] - [ExpectedException(typeof(ArgumentException))] - public void ThrowOnSerializerOptionsWithCustomSerializer() + public void ValidateThatCustomSerializerGetsOverriddenWhenSTJSerializerEnabled() { CosmosClientOptions options = new CosmosClientOptions() { Serializer = new CosmosJsonDotNetSerializer() }; - options.SerializerOptions = new CosmosSerializationOptions(); + options.UseSystemTextJsonForSerialization = true; + + CosmosClient client = new( + "https://fake-account.documents.azure.com:443/", + Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), + options + ); + + Assert.AreEqual(typeof(CosmosSystemTextJsonSerializer), client.ClientOptions.Serializer.GetType()); } [TestMethod] [ExpectedException(typeof(ArgumentException))] - public void ThrowOnCustomSerializerWithSerializerOptions() + public void ThrowOnSerializerOptionsWithCustomSerializer() { CosmosClientOptions options = new CosmosClientOptions() { - SerializerOptions = new CosmosSerializationOptions() + Serializer = new CosmosJsonDotNetSerializer() }; - options.Serializer = new CosmosJsonDotNetSerializer(); + options.SerializerOptions = new CosmosSerializationOptions(); } - + [TestMethod] [ExpectedException(typeof(ArgumentException))] - public void ThrowOnCustomSerializerWithSTJSerializerEnabled() + public void ThrowOnCustomSerializerWithSerializerOptions() { CosmosClientOptions options = new CosmosClientOptions() { - Serializer = new CosmosJsonDotNetSerializer() + SerializerOptions = new CosmosSerializationOptions() }; - options.SerializerOptions = new CosmosSerializationOptions(); - options.UseSystemTextJsonForSerialization = true; + options.Serializer = new CosmosJsonDotNetSerializer(); } [TestMethod] From 7460f30d791552033ab999aff16c3d475cb4eed5 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Mon, 22 Jul 2024 14:23:14 -0700 Subject: [PATCH 09/21] Code changes to address review comments. --- .../src/CosmosClientOptions.cs | 4 +- .../src/Resource/ClientContextCore.cs | 6 +++ .../CosmosClientOptionsUnitTests.cs | 40 +++++++++++++++++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 24479e9e60..c3e05329f1 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -556,10 +556,10 @@ public CosmosSerializationOptions SerializerOptions get => this.serializerOptions; set { - if (this.Serializer != null) + if (this.Serializer != null || this.UseSystemTextJsonForSerialization) { throw new ArgumentException( - $"{nameof(this.SerializerOptions)} is not compatible with {nameof(this.Serializer)}. Only one can be set. "); + $"{nameof(this.SerializerOptions)} is not compatible with {nameof(this.Serializer)} or {nameof(this.UseSystemTextJsonForSerialization)}. Only one can be set. "); } this.serializerOptions = value; diff --git a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs index 36238a6d74..abba5589b8 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs @@ -130,6 +130,12 @@ internal static CosmosClientContext Create( if (clientOptions.UseSystemTextJsonForSerialization) { + if (clientOptions.Serializer != null || clientOptions.SerializerOptions != null) + { + throw new ArgumentException( + $"{nameof(clientOptions.UseSystemTextJsonForSerialization)} is not compatible with {nameof(clientOptions.Serializer)} or {nameof(clientOptions.SerializerOptions)}. Only one can be set. "); + } + clientOptions.Serializer = new CosmosSystemTextJsonSerializer( new System.Text.Json.JsonSerializerOptions()); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs index f060fd2698..73abee13fc 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs @@ -484,11 +484,9 @@ public void ValidateThatCustomSerializerGetsOverriddenWhenSTJSerializerEnabled() { CosmosClientOptions options = new CosmosClientOptions() { - Serializer = new CosmosJsonDotNetSerializer() + UseSystemTextJsonForSerialization = true }; - options.UseSystemTextJsonForSerialization = true; - CosmosClient client = new( "https://fake-account.documents.azure.com:443/", Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), @@ -521,6 +519,42 @@ public void ThrowOnCustomSerializerWithSerializerOptions() options.Serializer = new CosmosJsonDotNetSerializer(); } + + [TestMethod] + [ExpectedException(typeof(ArgumentException))] + public void ThrowOnCustomSerializerWithSTJSerializerEnabled() + { + CosmosClientOptions options = new CosmosClientOptions() + { + Serializer = new CosmosJsonDotNetSerializer() + }; + + options.UseSystemTextJsonForSerialization = true; + + CosmosClient client = new( + "https://fake-account.documents.azure.com:443/", + Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), + options + ); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentException))] + public void ThrowOnSerializerOptionsWithSTJSerializerEnabled() + { + CosmosClientOptions options = new CosmosClientOptions() + { + SerializerOptions = new CosmosSerializationOptions(), + }; + + options.UseSystemTextJsonForSerialization = true; + + CosmosClient client = new( + "https://fake-account.documents.azure.com:443/", + Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), + options + ); + } [TestMethod] [ExpectedException(typeof(ArgumentNullException))] From 8c07f8f2bb13e42a0aa60f27e8e02bead14dab03 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Mon, 22 Jul 2024 16:07:39 -0700 Subject: [PATCH 10/21] Code changes to add serializer options as contract. --- .../src/CosmosClientOptions.cs | 24 ++++++++++++++++++- .../src/Resource/ClientContextCore.cs | 2 +- .../Contracts/DotNetSDKAPI.json | 19 +++++++++++++++ .../CosmosClientOptionsUnitTests.cs | 6 ++++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index c3e05329f1..2e05c9b06f 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos using System.Net; using System.Net.Http; using System.Net.Security; - using System.Security.Cryptography.X509Certificates; + using System.Security.Cryptography.X509Certificates; using Microsoft.Azure.Cosmos.Fluent; using Microsoft.Azure.Documents; using Microsoft.Azure.Documents.Client; @@ -405,6 +405,28 @@ public ConnectionMode ConnectionMode /// The default value is false /// public bool UseSystemTextJsonForSerialization { get; set; } = false; + + /// + /// Get or set the for the default STJ serializer . + /// + /// + /// An example on how to configure the STJ serialization option to ignore null values + /// + /// + /// + /// + public System.Text.Json.JsonSerializerOptions STJSerializerOptions { get; set; } /// /// Gets or sets the advanced replica selection flag. The advanced replica selection logic keeps track of the replica connection diff --git a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs index abba5589b8..bc3c02dbef 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs @@ -137,7 +137,7 @@ internal static CosmosClientContext Create( } clientOptions.Serializer = new CosmosSystemTextJsonSerializer( - new System.Text.Json.JsonSerializerOptions()); + clientOptions.STJSerializerOptions ?? new System.Text.Json.JsonSerializerOptions()); } CosmosSerializerCore serializerCore = CosmosSerializerCore.Create( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index c428e1046d..4e5453ef7e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -3000,6 +3000,18 @@ ], "MethodInfo": "System.String get_ApplicationRegion();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "System.Text.Json.JsonSerializerOptions get_STJSerializerOptions()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.Text.Json.JsonSerializerOptions get_STJSerializerOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.Text.Json.JsonSerializerOptions STJSerializerOptions": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.Text.Json.JsonSerializerOptions STJSerializerOptions;CanRead:True;CanWrite:True;System.Text.Json.JsonSerializerOptions get_STJSerializerOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_STJSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "System.TimeSpan get_RequestTimeout()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -3170,6 +3182,13 @@ ], "MethodInfo": "Void set_ServerCertificateCustomValidationCallback(System.Func`4[System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.X509Certificates.X509Chain,System.Net.Security.SslPolicyErrors,System.Boolean]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "Void set_STJSerializerOptions(System.Text.Json.JsonSerializerOptions)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Void set_STJSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "Void set_TokenCredentialBackgroundRefreshInterval(System.Nullable`1[System.TimeSpan])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs index 73abee13fc..1581d53a02 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs @@ -484,7 +484,11 @@ public void ValidateThatCustomSerializerGetsOverriddenWhenSTJSerializerEnabled() { CosmosClientOptions options = new CosmosClientOptions() { - UseSystemTextJsonForSerialization = true + UseSystemTextJsonForSerialization = true, + STJSerializerOptions = new System.Text.Json.JsonSerializerOptions() + { + PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase, + } }; CosmosClient client = new( From 79028727bd4fb975a174bc0cc4403fc22f30d1bd Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Mon, 22 Jul 2024 16:34:26 -0700 Subject: [PATCH 11/21] Code changes to add serializer options as public contract in builder. --- .../src/CosmosClientOptions.cs | 3 +- .../src/Fluent/CosmosClientBuilder.cs | 35 +++++++++++++------ ...TranslationWithCustomSerializerBaseline.cs | 5 ++- .../Contracts/DotNetSDKAPI.json | 10 ++++++ 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 2e05c9b06f..2635c7f466 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -425,7 +425,8 @@ public ConnectionMode ConnectionMode /// CosmosClient client = new CosmosClient("endpoint", "key", clientOptions); /// ]]> /// - /// + /// + /// If no serializer options is provided explicitly, then the default system text json serializer options will be used. public System.Text.Json.JsonSerializerOptions STJSerializerOptions { get; set; } /// diff --git a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs index 96dadcadf8..a7f867a513 100644 --- a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs +++ b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs @@ -647,6 +647,31 @@ public CosmosClientBuilder WithContentResponseOnWrite(bool contentResponseOnWrit this.clientOptions.EnableContentResponseOnWrite = contentResponseOnWrite; return this; } + + /// + /// Enables the usage of as the default + /// serializer. + /// + /// The object + public CosmosClientBuilder WithSystemTextJsonSerializerEnabled() + { + this.clientOptions.UseSystemTextJsonForSerialization = true; + return this; + } + + /// + /// Sets the serializer options for . If none provided + /// the default system text json serializer options will be used. + /// + /// An instance of + /// containing the system text json serializer options. + /// The object + public CosmosClientBuilder WithSystemTextJsonSerializerOptions( + System.Text.Json.JsonSerializerOptions stjSerializerOptions) + { + this.clientOptions.STJSerializerOptions = stjSerializerOptions; + return this; + } /// /// The event handler to be invoked before the request is sent. @@ -725,16 +750,6 @@ internal CosmosClientBuilder WithPartitionLevelFailoverEnabled() { this.clientOptions.EnablePartitionLevelFailover = true; return this; - } - - /// - /// Enables the usage of as the default - /// serializer. - /// - internal CosmosClientBuilder WithSystemTextJsonSerializerEnabled() - { - this.clientOptions.UseSystemTextJsonForSerialization = true; - return this; } /// diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs index a54612398f..fecd54f315 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs @@ -57,7 +57,10 @@ public async static Task Initialize(TestContext textContext) TestDb = await CosmosClient.CreateDatabaseAsync(dbName); CosmosDefaultSTJClient = TestCommon.CreateCosmosClient((cosmosClientBuilder) - => cosmosClientBuilder.WithSystemTextJsonSerializerEnabled(), + => cosmosClientBuilder + .WithSystemTextJsonSerializerEnabled() + .WithSystemTextJsonSerializerOptions( + new JsonSerializerOptions()), useCustomSeralizer: false); string dbNameSTJ = $"{nameof(LinqTranslationBaselineTests)}-{Guid.NewGuid():N}"; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 4e5453ef7e..ef3c0c88e6 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -4775,6 +4775,16 @@ "Attributes": [], "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithSerializerOptions(Microsoft.Azure.Cosmos.CosmosSerializationOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithSystemTextJsonSerializerEnabled()": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithSystemTextJsonSerializerEnabled();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithSystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithSystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithThrottlingRetryOptions(System.TimeSpan, Int32)": { "Type": "Method", "Attributes": [], From 8226f7ba69c9bd71609c2c114f205490c0812861 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Tue, 23 Jul 2024 11:07:46 -0700 Subject: [PATCH 12/21] Code changes to update contract to remove the STJ serializer boolean flag. --- .../src/CosmosClientOptions.cs | 21 +++-------- .../src/Fluent/CosmosClientBuilder.cs | 13 +------ .../src/Resource/ClientContextCore.cs | 6 ++-- ...inqAggregateCustomSerializationBaseline.cs | 3 +- ...TranslationWithCustomSerializerBaseline.cs | 1 - .../Contracts/DotNetSDKAPI.json | 36 ++++--------------- .../CosmosClientOptionsUnitTests.cs | 13 +++---- 7 files changed, 21 insertions(+), 72 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 2635c7f466..a52029c232 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -393,19 +393,6 @@ public ConnectionMode ConnectionMode /// public bool? EnableContentResponseOnWrite { get; set; } - /// - /// Gets or sets the boolean flag to indicate if the default STJ serializer needed to be - /// used for JSON serialization. - /// - /// - /// Note that, if this flag is set to true, then any custom seriliazer provided will be disregarded and overridden with the - /// default STJ serializer . - /// - /// - /// The default value is false - /// - public bool UseSystemTextJsonForSerialization { get; set; } = false; - /// /// Get or set the for the default STJ serializer . /// @@ -416,7 +403,7 @@ public ConnectionMode ConnectionMode /// CosmosClientOptions clientOptions = new CosmosClientOptions() /// { /// UseSystemTextJsonForSerialization = true, - /// STJSerializerOptions = new System.Text.Json.JsonSerializerOptions() + /// SystemTextJsonSerializerOptions = new System.Text.Json.JsonSerializerOptions() /// { /// DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull, /// } @@ -427,7 +414,7 @@ public ConnectionMode ConnectionMode /// /// /// If no serializer options is provided explicitly, then the default system text json serializer options will be used. - public System.Text.Json.JsonSerializerOptions STJSerializerOptions { get; set; } + public System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions { get; set; } /// /// Gets or sets the advanced replica selection flag. The advanced replica selection logic keeps track of the replica connection @@ -579,10 +566,10 @@ public CosmosSerializationOptions SerializerOptions get => this.serializerOptions; set { - if (this.Serializer != null || this.UseSystemTextJsonForSerialization) + if (this.Serializer != null || this.SystemTextJsonSerializerOptions != null) { throw new ArgumentException( - $"{nameof(this.SerializerOptions)} is not compatible with {nameof(this.Serializer)} or {nameof(this.UseSystemTextJsonForSerialization)}. Only one can be set. "); + $"{nameof(this.SerializerOptions)} is not compatible with {nameof(this.Serializer)} or {nameof(this.SystemTextJsonSerializerOptions)}. Only one can be set. "); } this.serializerOptions = value; diff --git a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs index a7f867a513..06a1bf58b0 100644 --- a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs +++ b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs @@ -648,17 +648,6 @@ public CosmosClientBuilder WithContentResponseOnWrite(bool contentResponseOnWrit return this; } - /// - /// Enables the usage of as the default - /// serializer. - /// - /// The object - public CosmosClientBuilder WithSystemTextJsonSerializerEnabled() - { - this.clientOptions.UseSystemTextJsonForSerialization = true; - return this; - } - /// /// Sets the serializer options for . If none provided /// the default system text json serializer options will be used. @@ -669,7 +658,7 @@ public CosmosClientBuilder WithSystemTextJsonSerializerEnabled() public CosmosClientBuilder WithSystemTextJsonSerializerOptions( System.Text.Json.JsonSerializerOptions stjSerializerOptions) { - this.clientOptions.STJSerializerOptions = stjSerializerOptions; + this.clientOptions.SystemTextJsonSerializerOptions = stjSerializerOptions; return this; } diff --git a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs index bc3c02dbef..bed0fd48b3 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs @@ -128,16 +128,16 @@ internal static CosmosClientContext Create( requestInvokerHandler = clientPipelineBuilder.Build(); } - if (clientOptions.UseSystemTextJsonForSerialization) + if (clientOptions.SystemTextJsonSerializerOptions != null) { if (clientOptions.Serializer != null || clientOptions.SerializerOptions != null) { throw new ArgumentException( - $"{nameof(clientOptions.UseSystemTextJsonForSerialization)} is not compatible with {nameof(clientOptions.Serializer)} or {nameof(clientOptions.SerializerOptions)}. Only one can be set. "); + $"{nameof(clientOptions.SystemTextJsonSerializerOptions)} is not compatible with {nameof(clientOptions.Serializer)} or {nameof(clientOptions.SerializerOptions)}. Only one can be set. "); } clientOptions.Serializer = new CosmosSystemTextJsonSerializer( - clientOptions.STJSerializerOptions ?? new System.Text.Json.JsonSerializerOptions()); + clientOptions.SystemTextJsonSerializerOptions ?? new System.Text.Json.JsonSerializerOptions()); } CosmosSerializerCore serializerCore = CosmosSerializerCore.Create( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs index caa79fbd44..f4e886ff7f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs @@ -64,7 +64,8 @@ public async static Task Initialize(TestContext textContext) testContainer = testDb.CreateContainerAsync(new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: "/Pk")).Result; stjClient = TestCommon.CreateCosmosClient((cosmosClientBuilder) - => cosmosClientBuilder.WithSystemTextJsonSerializerEnabled()); + => cosmosClientBuilder.WithSystemTextJsonSerializerOptions( + new JsonSerializerOptions())); // Set a callback to get the handle of the last executed query to do the verification // This is neede because aggregate queries return type is a scalar so it can't be used diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs index fecd54f315..48aed543bf 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqTranslationWithCustomSerializerBaseline.cs @@ -58,7 +58,6 @@ public async static Task Initialize(TestContext textContext) CosmosDefaultSTJClient = TestCommon.CreateCosmosClient((cosmosClientBuilder) => cosmosClientBuilder - .WithSystemTextJsonSerializerEnabled() .WithSystemTextJsonSerializerOptions( new JsonSerializerOptions()), useCustomSeralizer: false); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index ef3c0c88e6..3ab586875e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -2711,23 +2711,11 @@ ], "MethodInfo": "Boolean get_LimitToEndpoint();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Boolean get_UseSystemTextJsonForSerialization()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Boolean get_UseSystemTextJsonForSerialization();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Boolean LimitToEndpoint": { "Type": "Property", "Attributes": [], "MethodInfo": "Boolean LimitToEndpoint;CanRead:True;CanWrite:True;Boolean get_LimitToEndpoint();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_LimitToEndpoint(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Boolean UseSystemTextJsonForSerialization": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Boolean UseSystemTextJsonForSerialization;CanRead:True;CanWrite:True;Boolean get_UseSystemTextJsonForSerialization();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_UseSystemTextJsonForSerialization(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Int32 GatewayModeMaxConnectionLimit": { "Type": "Property", "Attributes": [], @@ -3000,17 +2988,17 @@ ], "MethodInfo": "System.String get_ApplicationRegion();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Text.Json.JsonSerializerOptions get_STJSerializerOptions()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.Text.Json.JsonSerializerOptions get_SystemTextJsonSerializerOptions()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "System.Text.Json.JsonSerializerOptions get_STJSerializerOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.Text.Json.JsonSerializerOptions get_SystemTextJsonSerializerOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Text.Json.JsonSerializerOptions STJSerializerOptions": { + "System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.Text.Json.JsonSerializerOptions STJSerializerOptions;CanRead:True;CanWrite:True;System.Text.Json.JsonSerializerOptions get_STJSerializerOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_STJSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions;CanRead:True;CanWrite:True;System.Text.Json.JsonSerializerOptions get_SystemTextJsonSerializerOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_SystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan get_RequestTimeout()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", @@ -3182,12 +3170,12 @@ ], "MethodInfo": "Void set_ServerCertificateCustomValidationCallback(System.Func`4[System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.X509Certificates.X509Chain,System.Net.Security.SslPolicyErrors,System.Boolean]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Void set_STJSerializerOptions(System.Text.Json.JsonSerializerOptions)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Void set_SystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "Void set_STJSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Void set_SystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Void set_TokenCredentialBackgroundRefreshInterval(System.Nullable`1[System.TimeSpan])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", @@ -3196,13 +3184,6 @@ ], "MethodInfo": "Void set_TokenCredentialBackgroundRefreshInterval(System.Nullable`1[System.TimeSpan]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Void set_UseSystemTextJsonForSerialization(Boolean)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Void set_UseSystemTextJsonForSerialization(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Void set_WebProxy(System.Net.IWebProxy)": { "Type": "Method", "Attributes": [], @@ -4775,11 +4756,6 @@ "Attributes": [], "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithSerializerOptions(Microsoft.Azure.Cosmos.CosmosSerializationOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithSystemTextJsonSerializerEnabled()": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithSystemTextJsonSerializerEnabled();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithSystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions)": { "Type": "Method", "Attributes": [], diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs index 1581d53a02..4c86b48cb6 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs @@ -484,8 +484,7 @@ public void ValidateThatCustomSerializerGetsOverriddenWhenSTJSerializerEnabled() { CosmosClientOptions options = new CosmosClientOptions() { - UseSystemTextJsonForSerialization = true, - STJSerializerOptions = new System.Text.Json.JsonSerializerOptions() + SystemTextJsonSerializerOptions = new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase, } @@ -530,11 +529,10 @@ public void ThrowOnCustomSerializerWithSTJSerializerEnabled() { CosmosClientOptions options = new CosmosClientOptions() { - Serializer = new CosmosJsonDotNetSerializer() + Serializer = new CosmosJsonDotNetSerializer(), + SystemTextJsonSerializerOptions = new System.Text.Json.JsonSerializerOptions(), }; - options.UseSystemTextJsonForSerialization = true; - CosmosClient client = new( "https://fake-account.documents.azure.com:443/", Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), @@ -548,11 +546,10 @@ public void ThrowOnSerializerOptionsWithSTJSerializerEnabled() { CosmosClientOptions options = new CosmosClientOptions() { - SerializerOptions = new CosmosSerializationOptions(), + SerializerOptions = new CosmosSerializationOptions(), + SystemTextJsonSerializerOptions = new System.Text.Json.JsonSerializerOptions(), }; - options.UseSystemTextJsonForSerialization = true; - CosmosClient client = new( "https://fake-account.documents.azure.com:443/", Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), From 6976042bd4434a9029253dc58ea5209439e687a4 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Tue, 23 Jul 2024 11:24:48 -0700 Subject: [PATCH 13/21] Code changes to update summary. --- Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs | 5 +++-- Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index a52029c232..2f4363904a 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -394,7 +394,7 @@ public ConnectionMode ConnectionMode public bool? EnableContentResponseOnWrite { get; set; } /// - /// Get or set the for the default STJ serializer . + /// Gets or sets the for the default STJ serializer . /// /// /// An example on how to configure the STJ serialization option to ignore null values @@ -413,7 +413,8 @@ public ConnectionMode ConnectionMode /// ]]> /// /// - /// If no serializer options is provided explicitly, then the default system text json serializer options will be used. + /// Note that if this option is provided, then the SDK will use the as the default serializer + /// and set the serializer options as the constructor args. public System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions { get; set; } /// diff --git a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs index 06a1bf58b0..140d5b9e70 100644 --- a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs +++ b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs @@ -650,7 +650,7 @@ public CosmosClientBuilder WithContentResponseOnWrite(bool contentResponseOnWrit /// /// Sets the serializer options for . If none provided - /// the default system text json serializer options will be used. + /// the default system text json serializer will not be used for serialization. /// /// An instance of /// containing the system text json serializer options. From 078ab71abac29fb96fa9d230cfa91c954174f264 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Tue, 23 Jul 2024 11:26:38 -0700 Subject: [PATCH 14/21] Code changes for minor cosmetic update. --- Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 2f4363904a..dd235eaa44 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -402,7 +402,6 @@ public ConnectionMode ConnectionMode /// Date: Tue, 23 Jul 2024 12:14:40 -0700 Subject: [PATCH 15/21] Code changes to fix xml comment. --- Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index dd235eaa44..2b1addd01d 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -413,7 +413,8 @@ public ConnectionMode ConnectionMode /// /// /// Note that if this option is provided, then the SDK will use the as the default serializer - /// and set the serializer options as the constructor args. + /// and set the serializer options as the constructor args. + /// public System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions { get; set; } /// From ef7073ac98cbad033bc7781e8f604ba242ddc858 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Tue, 23 Jul 2024 17:01:35 -0700 Subject: [PATCH 16/21] Code changes to move remarks to summary. Updated test. --- Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs | 9 ++++----- .../Linq/LinqAggregateCustomSerializationBaseline.cs | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 2b1addd01d..3289f989e2 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -394,7 +394,9 @@ public ConnectionMode ConnectionMode public bool? EnableContentResponseOnWrite { get; set; } /// - /// Gets or sets the for the default STJ serializer . + /// Gets or sets the for the default STJ serializer . + /// Note that if this option is provided, then the SDK will use the as the default serializer and set + /// the serializer options as the constructor args. /// /// /// An example on how to configure the STJ serialization option to ignore null values @@ -411,10 +413,7 @@ public ConnectionMode ConnectionMode /// CosmosClient client = new CosmosClient("endpoint", "key", clientOptions); /// ]]> /// - /// - /// Note that if this option is provided, then the SDK will use the as the default serializer - /// and set the serializer options as the constructor args. - /// + /// public System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions { get; set; } /// diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs index f4e886ff7f..54af230979 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqAggregateCustomSerializationBaseline.cs @@ -65,7 +65,8 @@ public async static Task Initialize(TestContext textContext) stjClient = TestCommon.CreateCosmosClient((cosmosClientBuilder) => cosmosClientBuilder.WithSystemTextJsonSerializerOptions( - new JsonSerializerOptions())); + new JsonSerializerOptions()), + useCustomSeralizer: false); // Set a callback to get the handle of the last executed query to do the verification // This is neede because aggregate queries return type is a scalar so it can't be used From 1f65a66c0f049265f44c33c1f1da0d463774c2d7 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Wed, 24 Jul 2024 10:59:51 -0700 Subject: [PATCH 17/21] Code changes to move the validation logic in cosmos client options. --- .../src/CosmosClientOptions.cs | 18 ++++++++++++++++-- .../src/Resource/ClientContextCore.cs | 8 +------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 3289f989e2..3cf8677674 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -60,7 +60,8 @@ public class CosmosClientOptions /// private int gatewayModeMaxConnectionLimit; private CosmosSerializationOptions serializerOptions; - private CosmosSerializer serializerInternal; + private CosmosSerializer serializerInternal; + private System.Text.Json.JsonSerializerOptions stjSerializerOptions; private ConnectionMode connectionMode; private Protocol connectionProtocol; @@ -414,7 +415,20 @@ public ConnectionMode ConnectionMode /// ]]> /// /// - public System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions { get; set; } + public System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions + { + get => this.stjSerializerOptions; + set + { + if (this.Serializer != null || this.SerializerOptions != null) + { + throw new ArgumentException( + $"{nameof(this.SystemTextJsonSerializerOptions)} is not compatible with {nameof(this.Serializer)} or {nameof(this.SerializerOptions)}. Only one can be set. "); + } + + this.stjSerializerOptions = value; + } + } /// /// Gets or sets the advanced replica selection flag. The advanced replica selection logic keeps track of the replica connection diff --git a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs index bed0fd48b3..c97497c751 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs @@ -130,14 +130,8 @@ internal static CosmosClientContext Create( if (clientOptions.SystemTextJsonSerializerOptions != null) { - if (clientOptions.Serializer != null || clientOptions.SerializerOptions != null) - { - throw new ArgumentException( - $"{nameof(clientOptions.SystemTextJsonSerializerOptions)} is not compatible with {nameof(clientOptions.Serializer)} or {nameof(clientOptions.SerializerOptions)}. Only one can be set. "); - } - clientOptions.Serializer = new CosmosSystemTextJsonSerializer( - clientOptions.SystemTextJsonSerializerOptions ?? new System.Text.Json.JsonSerializerOptions()); + clientOptions.SystemTextJsonSerializerOptions); } CosmosSerializerCore serializerCore = CosmosSerializerCore.Create( From 58981c20aeb4845bec96cc8acbb3383843f6a493 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Wed, 24 Jul 2024 11:10:53 -0700 Subject: [PATCH 18/21] Code changes to update contract. --- .../Contracts/DotNetSDKAPI.json | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 3ab586875e..a26496b749 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -2988,11 +2988,9 @@ ], "MethodInfo": "System.String get_ApplicationRegion();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Text.Json.JsonSerializerOptions get_SystemTextJsonSerializerOptions()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "System.Text.Json.JsonSerializerOptions get_SystemTextJsonSerializerOptions()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], + "Attributes": [], "MethodInfo": "System.Text.Json.JsonSerializerOptions get_SystemTextJsonSerializerOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions": { @@ -3170,11 +3168,9 @@ ], "MethodInfo": "Void set_ServerCertificateCustomValidationCallback(System.Func`4[System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.X509Certificates.X509Chain,System.Net.Security.SslPolicyErrors,System.Boolean]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Void set_SystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Void set_SystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions)": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], + "Attributes": [], "MethodInfo": "Void set_SystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "Void set_TokenCredentialBackgroundRefreshInterval(System.Nullable`1[System.TimeSpan])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { From ac5d07e943498e381a7ee2f30c7a3348d7080d8b Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Thu, 25 Jul 2024 23:15:22 -0700 Subject: [PATCH 19/21] Code changes to remove client context core logic in cosmos client options. --- .../src/CosmosClientOptions.cs | 28 ++++++++++--------- .../src/Fluent/CosmosClientBuilder.cs | 13 +++++---- .../src/Resource/ClientContextCore.cs | 6 ---- .../Contracts/DotNetSDKAPI.json | 19 +++++-------- .../CosmosClientOptionsUnitTests.cs | 6 ++-- 5 files changed, 32 insertions(+), 40 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 3cf8677674..afdfa3786d 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -395,17 +395,17 @@ public ConnectionMode ConnectionMode public bool? EnableContentResponseOnWrite { get; set; } /// - /// Gets or sets the for the default STJ serializer . - /// Note that if this option is provided, then the SDK will use the as the default serializer and set + /// Sets the for the System.Text.Json serializer. + /// Note that if this option is provided, then the SDK will use the System.Text.Json as the default serializer and set /// the serializer options as the constructor args. /// /// - /// An example on how to configure the STJ serialization option to ignore null values + /// An example on how to configure the System.Text.Json serializer options to ignore null values /// /// /// /// - public System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions + public System.Text.Json.JsonSerializerOptions UseSystemTextJsonSerializerWithOptions { - get => this.stjSerializerOptions; + private get => this.stjSerializerOptions; set - { + { if (this.Serializer != null || this.SerializerOptions != null) { throw new ArgumentException( - $"{nameof(this.SystemTextJsonSerializerOptions)} is not compatible with {nameof(this.Serializer)} or {nameof(this.SerializerOptions)}. Only one can be set. "); + $"{nameof(this.UseSystemTextJsonSerializerWithOptions)} is not compatible with {nameof(this.Serializer)} or {nameof(this.SerializerOptions)}. Only one can be set. "); } - this.stjSerializerOptions = value; + this.stjSerializerOptions = value; + this.serializerInternal = new CosmosSystemTextJsonSerializer( + this.stjSerializerOptions); } } @@ -580,10 +582,10 @@ public CosmosSerializationOptions SerializerOptions get => this.serializerOptions; set { - if (this.Serializer != null || this.SystemTextJsonSerializerOptions != null) + if (this.Serializer != null || this.UseSystemTextJsonSerializerWithOptions != null) { throw new ArgumentException( - $"{nameof(this.SerializerOptions)} is not compatible with {nameof(this.Serializer)} or {nameof(this.SystemTextJsonSerializerOptions)}. Only one can be set. "); + $"{nameof(this.SerializerOptions)} is not compatible with {nameof(this.Serializer)} or {nameof(this.UseSystemTextJsonSerializerWithOptions)}. Only one can be set. "); } this.serializerOptions = value; @@ -615,10 +617,10 @@ public CosmosSerializer Serializer get => this.serializerInternal; set { - if (this.SerializerOptions != null) + if (this.SerializerOptions != null || this.UseSystemTextJsonSerializerWithOptions != null) { throw new ArgumentException( - $"{nameof(this.Serializer)} is not compatible with {nameof(this.SerializerOptions)}. Only one can be set. "); + $"{nameof(this.Serializer)} is not compatible with {nameof(this.SerializerOptions)} or {nameof(this.UseSystemTextJsonSerializerWithOptions)}. Only one can be set. "); } this.serializerInternal = value; diff --git a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs index 140d5b9e70..c614068fae 100644 --- a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs +++ b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs @@ -646,19 +646,20 @@ public CosmosClientBuilder WithContentResponseOnWrite(bool contentResponseOnWrit { this.clientOptions.EnableContentResponseOnWrite = contentResponseOnWrite; return this; - } + } /// - /// Sets the serializer options for . If none provided - /// the default system text json serializer will not be used for serialization. + /// Configures the to use System.Text.Json for serialization. + /// Use to use System.Text.Json with a default configuration. + /// If no options are specified, Newtonsoft.Json will be used for serialization instead. /// - /// An instance of + /// An instance of /// containing the system text json serializer options. /// The object public CosmosClientBuilder WithSystemTextJsonSerializerOptions( - System.Text.Json.JsonSerializerOptions stjSerializerOptions) + System.Text.Json.JsonSerializerOptions serializerOptions) { - this.clientOptions.SystemTextJsonSerializerOptions = stjSerializerOptions; + this.clientOptions.UseSystemTextJsonSerializerWithOptions = serializerOptions; return this; } diff --git a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs index c97497c751..a8cc0d59dc 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs @@ -128,12 +128,6 @@ internal static CosmosClientContext Create( requestInvokerHandler = clientPipelineBuilder.Build(); } - if (clientOptions.SystemTextJsonSerializerOptions != null) - { - clientOptions.Serializer = new CosmosSystemTextJsonSerializer( - clientOptions.SystemTextJsonSerializerOptions); - } - CosmosSerializerCore serializerCore = CosmosSerializerCore.Create( clientOptions.Serializer, clientOptions.SerializerOptions); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index a26496b749..5f43ecd494 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -2988,15 +2988,10 @@ ], "MethodInfo": "System.String get_ApplicationRegion();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Text.Json.JsonSerializerOptions get_SystemTextJsonSerializerOptions()": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.Text.Json.JsonSerializerOptions get_SystemTextJsonSerializerOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions": { + "System.Text.Json.JsonSerializerOptions UseSystemTextJsonSerializerWithOptions": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.Text.Json.JsonSerializerOptions SystemTextJsonSerializerOptions;CanRead:True;CanWrite:True;System.Text.Json.JsonSerializerOptions get_SystemTextJsonSerializerOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_SystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.Text.Json.JsonSerializerOptions UseSystemTextJsonSerializerWithOptions;CanRead:True;CanWrite:True;Void set_UseSystemTextJsonSerializerWithOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan get_RequestTimeout()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", @@ -3168,11 +3163,6 @@ ], "MethodInfo": "Void set_ServerCertificateCustomValidationCallback(System.Func`4[System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.X509Certificates.X509Chain,System.Net.Security.SslPolicyErrors,System.Boolean]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Void set_SystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "Void set_SystemTextJsonSerializerOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Void set_TokenCredentialBackgroundRefreshInterval(System.Nullable`1[System.TimeSpan])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -3180,6 +3170,11 @@ ], "MethodInfo": "Void set_TokenCredentialBackgroundRefreshInterval(System.Nullable`1[System.TimeSpan]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "Void set_UseSystemTextJsonSerializerWithOptions(System.Text.Json.JsonSerializerOptions)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Void set_UseSystemTextJsonSerializerWithOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "Void set_WebProxy(System.Net.IWebProxy)": { "Type": "Method", "Attributes": [], diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs index 4c86b48cb6..074d182294 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs @@ -484,7 +484,7 @@ public void ValidateThatCustomSerializerGetsOverriddenWhenSTJSerializerEnabled() { CosmosClientOptions options = new CosmosClientOptions() { - SystemTextJsonSerializerOptions = new System.Text.Json.JsonSerializerOptions() + UseSystemTextJsonSerializerWithOptions = new System.Text.Json.JsonSerializerOptions() { PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase, } @@ -530,7 +530,7 @@ public void ThrowOnCustomSerializerWithSTJSerializerEnabled() CosmosClientOptions options = new CosmosClientOptions() { Serializer = new CosmosJsonDotNetSerializer(), - SystemTextJsonSerializerOptions = new System.Text.Json.JsonSerializerOptions(), + UseSystemTextJsonSerializerWithOptions = new System.Text.Json.JsonSerializerOptions(), }; CosmosClient client = new( @@ -547,7 +547,7 @@ public void ThrowOnSerializerOptionsWithSTJSerializerEnabled() CosmosClientOptions options = new CosmosClientOptions() { SerializerOptions = new CosmosSerializationOptions(), - SystemTextJsonSerializerOptions = new System.Text.Json.JsonSerializerOptions(), + UseSystemTextJsonSerializerWithOptions = new System.Text.Json.JsonSerializerOptions(), }; CosmosClient client = new( From 77bf9ec50eebbefdd405d6d297049328aa64c457 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Mon, 29 Jul 2024 11:06:12 -0700 Subject: [PATCH 20/21] Code changes to update some tests. --- .../CosmosClientOptionsUnitTests.cs | 72 +++++++++++-------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs index 074d182294..c27ca8abf1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs @@ -523,40 +523,56 @@ public void ThrowOnCustomSerializerWithSerializerOptions() options.Serializer = new CosmosJsonDotNetSerializer(); } - [TestMethod] + [TestMethod] + [DataRow(false, DisplayName = "Test when the client options order is maintained")] + [DataRow(true, DisplayName = "Test when the client options order is reversed")] [ExpectedException(typeof(ArgumentException))] - public void ThrowOnCustomSerializerWithSTJSerializerEnabled() - { - CosmosClientOptions options = new CosmosClientOptions() - { - Serializer = new CosmosJsonDotNetSerializer(), - UseSystemTextJsonSerializerWithOptions = new System.Text.Json.JsonSerializerOptions(), - }; - - CosmosClient client = new( - "https://fake-account.documents.azure.com:443/", - Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), - options - ); + public void ThrowOnCustomSerializerWithSTJSerializerEnabled( + bool reverseOrder) + { + if (reverseOrder) + { + CosmosClientOptions options = new CosmosClientOptions() + { + Serializer = new CosmosJsonDotNetSerializer(), + UseSystemTextJsonSerializerWithOptions = new System.Text.Json.JsonSerializerOptions(), + }; + } + else + { + CosmosClientOptions options = new CosmosClientOptions() + { + UseSystemTextJsonSerializerWithOptions = new System.Text.Json.JsonSerializerOptions(), + Serializer = new CosmosJsonDotNetSerializer(), + }; + } } - [TestMethod] + [TestMethod] + [DataRow(false, DisplayName = "Test when the client options order is maintained")] + [DataRow(true, DisplayName = "Test when the client options order is reversed")] [ExpectedException(typeof(ArgumentException))] - public void ThrowOnSerializerOptionsWithSTJSerializerEnabled() + public void ThrowOnSerializerOptionsWithSTJSerializerEnabled( + bool reverseOrder) { - CosmosClientOptions options = new CosmosClientOptions() - { - SerializerOptions = new CosmosSerializationOptions(), - UseSystemTextJsonSerializerWithOptions = new System.Text.Json.JsonSerializerOptions(), - }; - - CosmosClient client = new( - "https://fake-account.documents.azure.com:443/", - Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())), - options - ); + if (reverseOrder) + { + CosmosClientOptions options = new CosmosClientOptions() + { + SerializerOptions = new CosmosSerializationOptions(), + UseSystemTextJsonSerializerWithOptions = new System.Text.Json.JsonSerializerOptions(), + }; + } + else + { + CosmosClientOptions options = new CosmosClientOptions() + { + UseSystemTextJsonSerializerWithOptions = new System.Text.Json.JsonSerializerOptions(), + SerializerOptions = new CosmosSerializationOptions(), + }; + } } - + [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void ThrowOnNullTokenCredential() From f246ba886d7bd2ff51f636fb5e68c3b9b211fca3 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Mon, 29 Jul 2024 11:36:16 -0700 Subject: [PATCH 21/21] Code changes to update contract. Made cosmetic changes. --- Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs | 4 ++-- .../Contracts/DotNetSDKAPI.json | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index afdfa3786d..35dae71952 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos using System.Net; using System.Net.Http; using System.Net.Security; - using System.Security.Cryptography.X509Certificates; + using System.Security.Cryptography.X509Certificates; using Microsoft.Azure.Cosmos.Fluent; using Microsoft.Azure.Documents; using Microsoft.Azure.Documents.Client; @@ -417,7 +417,7 @@ public ConnectionMode ConnectionMode /// public System.Text.Json.JsonSerializerOptions UseSystemTextJsonSerializerWithOptions { - private get => this.stjSerializerOptions; + get => this.stjSerializerOptions; set { if (this.Serializer != null || this.SerializerOptions != null) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 5f43ecd494..2cc3fd8de5 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -2988,10 +2988,15 @@ ], "MethodInfo": "System.String get_ApplicationRegion();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "System.Text.Json.JsonSerializerOptions get_UseSystemTextJsonSerializerWithOptions()": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.Text.Json.JsonSerializerOptions get_UseSystemTextJsonSerializerWithOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "System.Text.Json.JsonSerializerOptions UseSystemTextJsonSerializerWithOptions": { "Type": "Property", "Attributes": [], - "MethodInfo": "System.Text.Json.JsonSerializerOptions UseSystemTextJsonSerializerWithOptions;CanRead:True;CanWrite:True;Void set_UseSystemTextJsonSerializerWithOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "System.Text.Json.JsonSerializerOptions UseSystemTextJsonSerializerWithOptions;CanRead:True;CanWrite:True;System.Text.Json.JsonSerializerOptions get_UseSystemTextJsonSerializerWithOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_UseSystemTextJsonSerializerWithOptions(System.Text.Json.JsonSerializerOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, "System.TimeSpan get_RequestTimeout()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method",