JMS
JMS

Reputation: 33

.Net 5 Azure functions Json Settings

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

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

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

Related Questions