This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code removed for bravity | |
public sealed class CosmosJsonDotNetSerializer : CosmosSerializer | |
{ | |
// Code removed for bravity | |
public override T FromStream<T>(Stream stream) | |
{ | |
using (stream) | |
{ | |
if (typeof(Stream).IsAssignableFrom(typeof(T))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order | |
{ | |
[JsonProperty("id")] | |
public string Id { get; set; } | |
public string Name { get; set; } | |
public OrderStatus OrderStatus { get; set; } | |
public int SchemaVersion {get; set;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrderV1 | |
{ | |
[JsonProperty("id")] | |
public string Id { get; set; } | |
public string OrderName { get; set; } | |
public bool HasShipped { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order | |
{ | |
[JsonProperty("id")] | |
public string Id { get; set; } | |
[Obsolete("Order name is obsolete, use Name instead")] | |
public string OrderName { get; set; } | |
[Obsolete("HasShipped is obsolete, set OrderStatus as Shipped Instead")] | |
public bool HasShipped { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cosmosClient = new CosmosClient("<cosmosDBConnectionString>", | |
new CosmosClientOptions | |
{ | |
Serializer = new CosmosSystemTextJsonSerializer(new JsonSerializerOptions | |
{ | |
// Update your JSON Serializer options here. | |
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | |
Converters = | |
{ | |
new JsonStringEnumConverter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.Text.Json; | |
using Azure.Core.Serialization; | |
using Microsoft.Azure.Cosmos; | |
/// <remarks> | |
// See: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos.Samples/Usage/SystemTextJson/CosmosSystemTextJsonSerializer.cs | |
/// </remarks> | |
public sealed class CosmosSystemTextJsonSerializer : CosmosSerializer | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cosmosClient = new CosmosClient("<cosmosDBConnectionString>", | |
new CosmosClientOptions | |
{ | |
Serializer = new CosmosJsonDotNetSerializer(new JsonSerializerSettings | |
{ | |
// Update your JSON Serializer Settings here. | |
TypeNameHandling = TypeNameHandling.Auto, | |
ReferenceLoopHandling = ReferenceLoopHandling.Error, | |
PreserveReferencesHandling = PreserveReferencesHandling.None, | |
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Text; | |
using Microsoft.Azure.Cosmos; | |
using Newtonsoft.Json; | |
/// <summary> | |
/// Azure Cosmos DB does not expose a default implementation of CosmosSerializer that is required to set the custom JSON serializer settings. | |
/// To fix this, we have to create our own implementation inspired internal implementation from SDK library. | |
/// <remarks> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
. | |
. | |
services.AddSingleton<IExceptionHandler, ExceptionHandler>(); | |
. | |
. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public interface IExceptionHandler | |
{ | |
public Error HandleException(Exception exception); | |
} |