Skip to content

Instantly share code, notes, and snippets.

@goncalo-oliveira
Last active August 11, 2021 11:43
Show Gist options
  • Save goncalo-oliveira/9b0234e167b953f3dffd59cc64167423 to your computer and use it in GitHub Desktop.
Save goncalo-oliveira/9b0234e167b953f3dffd59cc64167423 to your computer and use it in GitHub Desktop.
Configuring JsonOptions with ASPNET Functions
namespace OpenFaaS
{
public class Startup
{
...
public void ConfigureServices( IServiceCollection services )
{
/*
we don't have access to IMvcBuilder to use .AddJsonOptions extensions
but we can do the below instead. This particular example sets
camel casing, insensitive property names and ignore nulls
*/
services.Configure<JsonOptions>( options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
} );
}
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment