Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] SystemTextJsonSerializer: Adds STJ Serializer #4332

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bf78e7c
Code changes to add default STJ serializer.
kundadebdatta Feb 27, 2024
306b929
Code changes to add tests for STJ serializer.
kundadebdatta Feb 28, 2024
49844eb
Code changes to rename files.
kundadebdatta Mar 11, 2024
d49dff9
Code changes to clean up files.
kundadebdatta Mar 11, 2024
2d17302
Code changes to add more tests.
kundadebdatta Mar 11, 2024
c78093a
Merge branch 'master' into users/kundadebdatta/4330_add_default_stj_s…
kundadebdatta Mar 11, 2024
004d08d
Code changes to update respective contracts.
kundadebdatta Mar 11, 2024
3a728b1
Code changes to add more documentation.
kundadebdatta Mar 20, 2024
089095c
Code changes to add LINQ tests. Addressing few review comments.
kundadebdatta Apr 11, 2024
8b208de
Code changes to fix build failures.
kundadebdatta Apr 11, 2024
ca3b6a6
Code changes to update contract files.
kundadebdatta Apr 12, 2024
73178e0
Code changes to add more LINQ specific test cases.
kundadebdatta Apr 15, 2024
683ca13
Code changes to address review comments.
kundadebdatta Apr 15, 2024
61171cd
Merge branch 'master' into users/kundadebdatta/4330_add_default_stj_s…
kundadebdatta Apr 15, 2024
5df9c07
Merge branch 'master' into users/kundadebdatta/4330_add_default_stj_s…
kundadebdatta May 9, 2024
cdbf98c
Code changes to port some of the optimizations from Maya.
kundadebdatta May 9, 2024
4938ac3
Merge branch 'master' into users/kundadebdatta/4330_add_default_stj_s…
kundadebdatta May 10, 2024
37009ca
Code changes to update the remarks since the changes from maya will c…
kundadebdatta May 10, 2024
1ff1f06
Code changes to address review comments.
kundadebdatta Jun 17, 2024
0a07f19
Code changes to update preview and GA contracts.
kundadebdatta Jun 17, 2024
5327c33
Merge branch 'master' into users/kundadebdatta/4330_add_default_stj_s…
kundadebdatta Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------

namespace Microsoft.Azure.Cosmos
{
using System;
using System.IO;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using global::Azure.Core.Serialization;

/// <summary>
/// This class provides a default implementation of STJ Cosmos Linq Serializer.
kundadebdatta marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public class CosmosDefaultSystemTextJsonSerializer : CosmosLinqSerializer
kundadebdatta marked this conversation as resolved.
Show resolved Hide resolved
kundadebdatta marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// A read-only instance of <see cref="JsonObjectSerializer"/>.
/// </summary>
private readonly JsonObjectSerializer systemTextJsonSerializer;

/// <summary>
/// Creates an instance of <see cref="CosmosDefaultSystemTextJsonSerializer"/>
/// with the default values for the Cosmos SDK
/// </summary>
/// <param name="jsonSerializerOptions">An instance of <see cref="JsonSerializerOptions"/> containing the json serialization options.</param>
public CosmosDefaultSystemTextJsonSerializer(
JsonSerializerOptions jsonSerializerOptions)
kundadebdatta marked this conversation as resolved.
Show resolved Hide resolved
{
this.systemTextJsonSerializer = new JsonObjectSerializer(jsonSerializerOptions);
}

/// <inheritdoc/>
public override T FromStream<T>(Stream stream)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));

using (stream)
{
if (stream.CanSeek && stream.Length == 0)
{
return default;
}

if (typeof(Stream).IsAssignableFrom(typeof(T)))
{
return (T)(object)stream;
}

return (T)this.systemTextJsonSerializer.Deserialize(stream, typeof(T), default);
}
}

/// <inheritdoc/>
public override Stream ToStream<T>(T input)
{
MemoryStream streamPayload = new ();
this.systemTextJsonSerializer.Serialize(
stream: streamPayload,
value: input,
inputType: input.GetType(),
cancellationToken: default);

streamPayload.Position = 0;
return streamPayload;
}

/// <inheritdoc/>
public override string SerializeMemberName(MemberInfo memberInfo)
{
JsonExtensionDataAttribute jsonExtensionDataAttribute =
memberInfo.GetCustomAttribute<JsonExtensionDataAttribute>(true);

if (jsonExtensionDataAttribute != null)
{
return null;
}

JsonPropertyNameAttribute jsonPropertyNameAttribute = memberInfo.GetCustomAttribute<JsonPropertyNameAttribute>(true);

string memberName = !string.IsNullOrEmpty(jsonPropertyNameAttribute?.Name)
? jsonPropertyNameAttribute.Name
: memberInfo.Name;

return memberName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,32 @@
},
"NestedTypes": {}
},
"Microsoft.Azure.Cosmos.CosmosDefaultSystemTextJsonSerializer;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.CosmosDiagnostics;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": {
"Subclasses": {},
"Members": {
Expand Down Expand Up @@ -3407,7 +3433,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.CosmosDefaultSystemTextJsonSerializer;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",
Expand Down Expand Up @@ -3657,8 +3710,61 @@
},
"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": {
"Microsoft.Azure.Cosmos.CosmosDefaultSystemTextJsonSerializer;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.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.CosmosDefaultSystemTextJsonSerializer;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",
Expand Down
Loading
Loading