Skip to content

Commit

Permalink
Code changes to address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
kundadebdatta committed Jun 17, 2024
1 parent 37009ca commit 1ff1f06
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// This class provides a default implementation of System.Text.Json Cosmos Linq Serializer.
/// </summary>
public class CosmosSystemTextJsonSerializer : CosmosLinqSerializer
internal class CosmosSystemTextJsonSerializer : CosmosLinqSerializer
{
/// <summary>
/// A read-only instance of <see cref="JsonSerializerOptions"/>.
Expand All @@ -25,7 +25,7 @@ public class CosmosSystemTextJsonSerializer : CosmosLinqSerializer
/// 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 CosmosSystemTextJsonSerializer(
internal CosmosSystemTextJsonSerializer(
JsonSerializerOptions jsonSerializerOptions)
{
this.jsonSerializerOptions = jsonSerializerOptions;
Expand All @@ -37,14 +37,14 @@ public override T FromStream<T>(Stream stream)
if (stream == null)
throw new ArgumentNullException(nameof(stream));

if (stream.CanSeek && stream.Length == 0)
if (typeof(Stream).IsAssignableFrom(typeof(T)))
{
return default;
return (T)(object)stream;
}

if (typeof(Stream).IsAssignableFrom(typeof(T)))
if (stream.CanSeek && stream.Length == 0)
{
return (T)(object)stream;
return default;
}

using (stream)
Expand All @@ -60,10 +60,7 @@ public override Stream ToStream<T>(T input)
MemoryStream streamPayload = new ();
using Utf8JsonWriter writer = new (streamPayload);

JsonSerializer.Serialize(
writer: writer,
value: input,
options: this.jsonSerializerOptions);
JsonSerializer.Serialize(writer, input, this.jsonSerializerOptions);

streamPayload.Position = 0;
return streamPayload;
Expand Down

0 comments on commit 1ff1f06

Please sign in to comment.