using System; using System.IO; using System.Text.Json; using Microsoft.Azure.Cosmos; namespace CosmosDB3Test { public class TextJsonSerializer : CosmosSerializer { private JsonSerializerOptions options = new JsonSerializerOptions() { IgnoreNullValues = true, PropertyNameCaseInsensitive = true }; public override T FromStream(Stream stream) { using (stream) { return JsonSerializer.DeserializeAsync(stream, this.options).GetAwaiter().GetResult(); } } public override Stream ToStream(T input) { MemoryStream stream = new MemoryStream(); JsonSerializer.SerializeAsync(stream, input, this.options).GetAwaiter().GetResult(); return stream; } } }