Last active
August 11, 2021 11:43
-
-
Save goncalo-oliveira/9b0234e167b953f3dffd59cc64167423 to your computer and use it in GitHub Desktop.
Configuring JsonOptions with ASPNET Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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