Azure Functions out-of-process .NET language worker
MIT License
427
stars
182
forks
source link
Strings containing a DateTime formatted value are parsed and converted to server's time zone even when Newtonsoft JSON serializer is used and date parsing is disabled when using a Cosmos DB trigger #2442
Configure functions worker defaults in Program.cs to use Newtonsoft JSON as a serializer and set DateParseHandling to DateParseHandling.None
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(builder =>
{
builder.Services.Configure<WorkerOptions>(options =>
{
var settings = NewtonsoftJsonObjectSerializer.CreateJsonSerializerSettings();
settings.DateParseHandling = DateParseHandling.None;
options.Serializer = new NewtonsoftJsonObjectSerializer(settings);
});
})
.Build();
host.Run();
Run the function
Create a new document containing data provided below in container MyContainer of the MyDatabase database of your Cosmos DB emulator to trigger function execution:
Description
Context of our problem:
JObject
to be used by Cosmos DB trigger instead of a POCO typeDateParseHandling.None
inJsonSerializerSettings
The problem:
Strings containing dates are converted to server's time zone.
Steps to reproduce
IReadOnlyList<JObject>
:MyDatabase
and a new containerMyContainer
in your Cosmos DB emulatorCosmosDbConnectionString
inlocal.settings.json
to your Cosmos DB emulator connection stringMicrosoft.Azure.Core.NewtonsoftJson
Program.cs
to use Newtonsoft JSON as a serializer and setDateParseHandling
toDateParseHandling.None
MyContainer
of theMyDatabase
database of your Cosmos DB emulator to trigger function execution: