【发布时间】:2019-03-08 04:01:33
【问题描述】:
我有一个带有 CosmosDB 输出绑定的 Azure 函数,如下所示:
public static class ComponentDesignHttpTrigger
{
[FunctionName("ComponentDesignInserter-Http-From-ComponentDesign")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "fromComponentDesign")] HttpRequest request,
[CosmosDB(
databaseName: StorageFramework.CosmosDb.DatabaseId,
collectionName: Storage.ComponentDesignCollectionId,
ConnectionStringSetting = "CosmosDBConnection")] out ComponentDesign componentDesignToInsert,
ILogger log)
{
var requestBody = new StreamReader(request.Body).ReadToEnd();
componentDesignToInsert = JsonConvert.DeserializeObject<ComponentDesign>(requestBody);
return new OkObjectResult(componentDesignToInsert);
}
}
在这个函数中componentDesignToInsert在函数执行完成后会自动序列化并放入CosmosDB。但是默认的序列化并没有把东西放在camelCase中。对于此 Json.NET,您可以提供自定义序列化程序设置,如下所示:
var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var json = JsonConvert.SerializeObject(yourObject, settings);
但我不确定如何将它与我的输出绑定集成。我怎样才能做到这一点?
【问题讨论】:
标签: azure json.net azure-functions azure-cosmosdb azure-functions-core-tools