Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
921 views
in Technique[技术] by (71.8m points)

azure cosmosdb - Custom serialisation of C# poco's for DocumentDb

Is it possible to change the default serialisation of C# poco's for documentDb? The id-property for instance seem to be required to be lower case, but the default serialisation of the Id property is upper case. Ideally we would like all json properties to start with lower case characters. The only way we found so far is to decorate the properties with [JsonProperty(PropertyName = "id")] but it's not very elegant.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Currently you can't change the default serializer of DocumentDB, you can however serialize it using your own library or JSON.NET and store the JSON string to the collection by doing:

await client.CreateDocumentAsync(collectionLink, Resource.LoadFrom<Document>(stream)); 

where stream a stream to your json string (can be from a file, or from an in-memory string, etc). You can find more info on the internet archive's edition of my blog post, which used to reside here

Edit: JSON serializer settings is supported in the DocumentDB .NET SDK 1.16.0+. https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-dotnet


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...