diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs
index a9ef4569b5..3736f41cf5 100644
--- a/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs
+++ b/Microsoft.Azure.Cosmos/src/Query/Core/Metrics/IndexUtilizationInfo.cs
@@ -7,10 +7,10 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Metrics
using System.Collections.Generic;
using System.Linq;
using System.Text;
+ using System.Text.Json;
using Microsoft.Azure.Cosmos.Core;
- using Microsoft.Azure.Cosmos.Core.Utf8;
- using Newtonsoft.Json;
-
+ using Microsoft.Azure.Cosmos.Core.Utf8;
+
///
/// Query index utilization metrics in the Azure Cosmos database service.
///
@@ -36,7 +36,6 @@ sealed class IndexUtilizationInfo
/// The potential single indexes list
/// The potential composite indexes list
/// The utilized composite indexes list
- [JsonConstructor]
public IndexUtilizationInfo(
IReadOnlyList utilizedSingleIndexes,
IReadOnlyList potentialSingleIndexes,
@@ -74,16 +73,12 @@ internal static bool TryCreateFromDelimitedBase64String(string delimitedString,
// so this class exists solely for legacy support.
try
{
- string decodedString = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(delimitedString));
-
- result = JsonConvert.DeserializeObject(decodedString, new JsonSerializerSettings()
- {
- // Allowing null values to be resilient to Json structure change
- MissingMemberHandling = MissingMemberHandling.Ignore,
- NullValueHandling = NullValueHandling.Ignore,
- // Ignore parsing error encountered in desrialization
- Error = (sender, parsingErrorEvent) => parsingErrorEvent.ErrorContext.Handled = true
- }) ?? IndexUtilizationInfo.Empty;
+ string decodedString = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(delimitedString));
+
+ // TODO - Allowing null values to be resilient to Json structure change
+ // TODO - Ignore parsing error encountered in desrialization
+ result = JsonSerializer.Deserialize(decodedString, CosmosSerializerContext.Default.IndexUtilizationInfo) ??
+ IndexUtilizationInfo.Empty;
return true;
}
diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs
index b0cec3b2b9..f0e962026a 100644
--- a/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs
+++ b/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPartitionProvider.cs
@@ -16,11 +16,11 @@ namespace Microsoft.Azure.Cosmos.Query.Core.QueryPlan
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.Azure.Cosmos.Routing;
using Microsoft.Azure.Cosmos.Tracing;
- using Newtonsoft.Json;
+ using System.Text.Json;
using PartitionKeyDefinition = Documents.PartitionKeyDefinition;
using PartitionKeyInternal = Documents.Routing.PartitionKeyInternal;
using PartitionKind = Documents.PartitionKind;
- using ServiceInteropWrapper = Documents.ServiceInteropWrapper;
+ using ServiceInteropWrapper = Documents.ServiceInteropWrapper;
internal sealed class QueryPartitionProvider : IDisposable
{
@@ -65,7 +65,9 @@ public QueryPartitionProvider(IDictionary queryengineConfigurati
#endif
this.disposed = false;
- this.queryengineConfiguration = JsonConvert.SerializeObject(queryengineConfiguration);
+ this.queryengineConfiguration = JsonSerializer.Serialize(
+ queryengineConfiguration,
+ CosmosSerializerContext.Default.DictionaryStringObject);
this.ClientDisableOptimisticDirectExecution = GetClientDisableOptimisticDirectExecution((IReadOnlyDictionary)queryengineConfiguration);
this.serviceProvider = IntPtr.Zero;
@@ -94,7 +96,9 @@ public void Update(IDictionary queryengineConfiguration)
{
lock (this.serviceProviderStateLock)
{
- string newConfiguration = JsonConvert.SerializeObject(queryengineConfiguration);
+ string newConfiguration = JsonSerializer.Serialize(
+ queryengineConfiguration,
+ CosmosSerializerContext.Default.DictionaryStringObject);
if (!string.Equals(this.queryengineConfiguration, newConfiguration))
{
@@ -231,7 +235,9 @@ internal TryCatch TryGetPartitionedQueryE
uint serializedQueryExecutionInfoResultLength;
string vectorEmbeddingPolicyString = vectorEmbeddingPolicy != null ?
- JsonConvert.SerializeObject(vectorEmbeddingPolicy) :
+ JsonSerializer.Serialize(
+ vectorEmbeddingPolicy,
+ CosmosSerializerContext.Default.VectorEmbeddingPolicy) :
null;
unsafe
@@ -314,13 +320,9 @@ internal TryCatch TryGetPartitionedQueryE
}
PartitionedQueryExecutionInfoInternal queryInfoInternal =
- JsonConvert.DeserializeObject(
- serializedQueryExecutionInfo,
- new JsonSerializerSettings
- {
- DateParseHandling = DateParseHandling.None,
- MaxDepth = 64, // https://github.com/advisories/GHSA-5crp-9r3c-p9vr
- });
+ JsonSerializer.Deserialize(
+ serializedQueryExecutionInfo,
+ CosmosSerializerContext.Default.PartitionedQueryExecutionInfoInternal);
if (!this.ValidateQueryExecutionInfo(queryInfoInternal, out ArgumentException innerException))
{
diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/CosmosSerializerContext.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/CosmosSerializerContext.cs
index e06f3d9813..6e8c2ac64e 100644
--- a/Microsoft.Azure.Cosmos/src/Resource/Settings/CosmosSerializerContext.cs
+++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/CosmosSerializerContext.cs
@@ -10,7 +10,8 @@ namespace Microsoft.Azure.Cosmos
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
- using Microsoft.Azure.Cosmos.Query.Core;
+ using Microsoft.Azure.Cosmos.Query.Core;
+ using Microsoft.Azure.Cosmos.Query.Core.Metrics;
using Microsoft.Azure.Cosmos.Query.Core.Pipeline.CrossPartition.OrderBy;
using Microsoft.Azure.Cosmos.Query.Core.QueryClient;
using Microsoft.Azure.Cosmos.Query.Core.QueryPlan;
@@ -21,46 +22,48 @@ namespace Microsoft.Azure.Cosmos
using Microsoft.Azure.Documents;
[JsonSourceGenerationOptions(WriteIndented = true)]
+ [JsonSerializable(typeof(AccountConsistency))]
+ [JsonSerializable(typeof(AccountProperties))]
[JsonSerializable(typeof(AzureVMMetadata))]
- [JsonSerializable(typeof(ConsistencyConfig))]
- [JsonSerializable(typeof(GatewayConnectionConfig))]
- [JsonSerializable(typeof(OtherConnectionConfig))]
- [JsonSerializable(typeof(SqlQuerySpec))]
- [JsonSerializable(typeof(SqlParameterCollection))]
- [JsonSerializable(typeof(PartitionKeyDefinition))]
- [JsonSerializable(typeof(IndexingPolicy))]
- [JsonSerializable(typeof(GeospatialConfig))]
- [JsonSerializable(typeof(UniqueKeyPolicy))]
- [JsonSerializable(typeof(ConflictResolutionPolicy))]
[JsonSerializable(typeof(ClientEncryptionPolicy))]
- [JsonSerializable(typeof(VectorEmbeddingPolicy))]
+ [JsonSerializable(typeof(Collection))]
[JsonSerializable(typeof(Collection))]
- [JsonSerializable(typeof(List))]
+ [JsonSerializable(typeof(Collection))]
[JsonSerializable(typeof(CompositeContinuationToken))]
- [JsonSerializable(typeof(FullTextPolicy))]
+ [JsonSerializable(typeof(ConflictResolutionPolicy))]
+ [JsonSerializable(typeof(ConsistencyConfig))]
[JsonSerializable(typeof(ContainerProperties))]
- [JsonSerializable(typeof(PatchSpec))]
- [JsonSerializable(typeof(ThroughputProperties))]
- [JsonSerializable(typeof(TriggerProperties))]
- [JsonSerializable(typeof(StoredProcedureProperties))]
- [JsonSerializable(typeof(UserDefinedFunctionProperties))]
+ [JsonSerializable(typeof(CosmosQueryExecutionInfo))]
[JsonSerializable(typeof(DatabaseProperties))]
- [JsonSerializable(typeof(AccountProperties))]
- [JsonSerializable(typeof(Collection))]
- [JsonSerializable(typeof(AccountConsistency))]
- [JsonSerializable(typeof(ReplicationPolicy))]
- [JsonSerializable(typeof(ReadPolicy))]
+ [JsonSerializable(typeof(Dictionary))]
+ [JsonSerializable(typeof(Documents.Routing.Range))]
[JsonSerializable(typeof(FeedResource_Address))]
- [JsonSerializable(typeof(PartitionKeyRange))]
[JsonSerializable(typeof(FeedResource_PartitionKeyRange))]
- [JsonSerializable(typeof(Dictionary))]
- [JsonSerializable(typeof(Collection))]
- [JsonSerializable(typeof(PartitionedQueryExecutionInfo))]
+ [JsonSerializable(typeof(FullTextPolicy))]
+ [JsonSerializable(typeof(GatewayConnectionConfig))]
+ [JsonSerializable(typeof(GeospatialConfig))]
[JsonSerializable(typeof(HybridSearchQueryInfo))]
- [JsonSerializable(typeof(Documents.Routing.Range))]
- [JsonSerializable(typeof(QueryInfo))]
+ [JsonSerializable(typeof(IndexingPolicy))]
+ [JsonSerializable(typeof(IndexUtilizationInfo))]
[JsonSerializable(typeof(IReadOnlyList))]
- [JsonSerializable(typeof(CosmosQueryExecutionInfo))]
+ [JsonSerializable(typeof(List))]
+ [JsonSerializable(typeof(OtherConnectionConfig))]
+ [JsonSerializable(typeof(PartitionKeyDefinition))]
+ [JsonSerializable(typeof(PartitionKeyRange))]
+ [JsonSerializable(typeof(PartitionedQueryExecutionInfo))]
+ [JsonSerializable(typeof(PartitionedQueryExecutionInfoInternal))]
+ [JsonSerializable(typeof(PatchSpec))]
+ [JsonSerializable(typeof(QueryInfo))]
+ [JsonSerializable(typeof(ReadPolicy))]
+ [JsonSerializable(typeof(ReplicationPolicy))]
+ [JsonSerializable(typeof(SqlQuerySpec))]
+ [JsonSerializable(typeof(SqlParameterCollection))]
+ [JsonSerializable(typeof(StoredProcedureProperties))]
+ [JsonSerializable(typeof(ThroughputProperties))]
+ [JsonSerializable(typeof(TriggerProperties))]
+ [JsonSerializable(typeof(UniqueKeyPolicy))]
+ [JsonSerializable(typeof(UserDefinedFunctionProperties))]
+ [JsonSerializable(typeof(VectorEmbeddingPolicy))]
internal partial class CosmosSerializerContext : JsonSerializerContext
{
}
diff --git a/Microsoft.Azure.Cosmos/src/direct/VectorEmbeddingPolicy.cs b/Microsoft.Azure.Cosmos/src/direct/VectorEmbeddingPolicy.cs
index bcae7b4c71..ef3ab4fe5a 100644
--- a/Microsoft.Azure.Cosmos/src/direct/VectorEmbeddingPolicy.cs
+++ b/Microsoft.Azure.Cosmos/src/direct/VectorEmbeddingPolicy.cs
@@ -7,7 +7,7 @@ namespace Microsoft.Azure.Documents
using System;
using System.Collections.ObjectModel;
using System.Globalization;
- using Newtonsoft.Json;
+ using System.Text.Json.Serialization;
///
/// Represents the vector embedding policy configuration for specifying the vector embeddings on documents in the collection in the Azure Cosmos DB service.
@@ -27,7 +27,7 @@ public VectorEmbeddingPolicy()
///
/// Gets a collection of that contains the vector embeddings of documents in collection in the Azure Cosmos DB service.
///
- [JsonProperty(PropertyName = Constants.Properties.VectorEmbeddings)]
+ [JsonPropertyName(Constants.Properties.VectorEmbeddings)]
public Collection Embeddings
{
get