Azure Document Client忽略JsonProperty属性

我使用Azure Function应用。在应用程序中,我使用microsoft.Azure.DocumentDB v2.9.2包与CommosDB一起使用。我的实体是:

public abstract class Entity
{
    [JsonProperty("id")]
    public string id { get; set; }
}

public class MyLog : Entity
{
    [JsonProperty("createDate")]
    public DateTime CreateDate { get; set; }
}

当我用MyLog序列化Newtonsoft.Json时,我看到CreateDate属性是驼峰式的,看起来与JsonProperty中提到的完全一样,但是当我将实体写入CosmosDB时通过CreateDocumentAsync方法,我发现CreateDate现在是帕斯卡大小写,看起来像CreateDate。要提及的是,没有使用ContractResolver。我找不到其他任何可以将pascal大小写应用于实体序列化的地方。

[UPDATE]

运行测试时,我看到DB中的属性命名是正确的(考虑到JsonProperty)。仅当azure func写入数据库

时,这是错误的
var policy = new ConnectionPolicy();
policy.PreferredLocations.Add("Germany North");
documentClient = new DocumentClient(endPoint,key,policy);
await documentClient.OpenAsync();

...

await documentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName,collectionName),document);

[/ UPDATE]

有人可以建议其他哪些选项会导致这种行为吗?

woshiaitade12 回答:Azure Document Client忽略JsonProperty属性

因此,我找出了这种现象的原因。默认情况下,带有.NET 4.7.2的Azure Function v1使用DataContractJsonSerializer,并且不考虑JsonProperty属性。测试使用NewtonSoft json序列化程序,这就是使用属性的原因。

本文链接:https://www.f2er.com/2542727.html

大家都在问