Use custom JsonSerializerSettings with DocumentDb

2019-02-25 13:30发布

问题:

I would like to create a document using the DocumentDb API using custom JsonSerializerSettings. Can anyone tell me how I can do this?

I have tried setting

JsonConvert.DefaultSettings = () => {
    return new JsonSerializerSettings() {
        ContractResolver = new CamelCasePropertyNameContractResolver()
        };
    };

回答1:

The latest DocumentDB SDK (1.15.0) exposes now the JsonSerializerSettings.

You can define your custom settings when you create the DocumentClient instance:

DocumentClient yourClient = new DocumentClient(new Uri("Your Service Endpoint"), "Your Account Key", serializerSettings: new JsonSerializerSettings()
            {
                // Custom settings
            });