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

Categories

0 votes
1.0k 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...