Reputation: 33
Struggling to find how set the serialiser settings in .Net 5 Azure Functions
static Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureAppConfiguration(configurationBuilder =>
{
configurationBuilder.AddCommandLine(args);
})
.ConfigureFunctionsWorkerDefaults((hostBuilderContext, workerApplicationBuilder) =>
{
workerApplicationBuilder.UseFunctionExecutionMiddleware();
})
.ConfigureServices(services =>
{
})
.Build();
return host.RunAsync();
}
does anyone have an example?
Thanks
Upvotes: 1
Views: 320
Reputation: 30025
Please try the code below:
static async Task Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(builder => {
//use this code for json settings
builder.Services.AddMvcCore()
.AddNewtonsoftJson(option =>
{
option.SerializerSettings.Converters.Add(xxx);
});
})
.ConfigureServices(services =>
{
})
.Build();
await host.RunAsync();
}
Note that the package Microsoft.AspNetCore.Mvc.NewtonsoftJson should be installed.
Upvotes: 2