用于DocumentDb的C#poco的自定义序列化 [英] Custom serialisation of C# poco's for DocumentDb

查看:66
本文介绍了用于DocumentDb的C#poco的自定义序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改documentDb的C#poco的默认序列化?例如,似乎要求id属性为小写,但Id属性的默认序列化为大写.理想情况下,我们希望所有json属性都以小写字符开头.到目前为止,我们发现的唯一方法是用[JsonProperty(PropertyName ="id")]装饰属性,但这不是很优雅.

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.

推荐答案

当前您无法更改DocumentDB的默认序列化程序,但是可以使用自己的库或JSON.NET对其进行序列化并将JSON字符串存储到集合中通过这样做:

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)); 

在哪里将流流传输到您的json字符串(可以来自文件,也可以来自内存中的字符串,等等). 您可以在">经常驻留在此处

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

编辑:DocumentDB .NET SDK 1.16.0+支持JSON序列化程序设置. https://docs.microsoft.com/zh-cn/azure/cosmos-db/sql-api-sdk-dotnet

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

这篇关于用于DocumentDb的C#poco的自定义序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆