My .NET POCOs are in ProperCase
. My json is in camelCase
. How can I configure version 3.0 of the .NET SDK to convert when serializing/deserializing to/from Cosmos DB?
I know I can add the attribute [JsonProperty(PropertyName = "myProperty")]
to each property but how can I tell the SDK to do this for all properties by default?
I'm trying to get away from adding an attribute for this to every property.
var client = new CosmosClientBuilder("URI", "Key")
.WithSerializerOptions(new CosmosSerializationOptions { PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase })
.Build();
It's a bit quick and dirty but to keep you moving until Microsoft exposes the serializer settings of the default serializer, you could copy the existing CosmosJsonSerializer and pass in the JsonSerializerSettings to the constructor.
I've created a gist you can take here:
Newtonsoft JSON.NET Serializer for Cosmos .net SDK v3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With