Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 574a8cd

Browse files
committed
Aggiunta configurazione per JSON
1 parent 2b22495 commit 574a8cd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Json configuration
2+
3+
4+
## Registering services at Startup
5+
6+
```csharp
7+
public Startup(IConfiguration configuration)
8+
{
9+
Configuration = configuration;
10+
}
11+
12+
public IConfiguration Configuration { get; }
13+
14+
public void ConfigureServices(IServiceCollection services)
15+
{
16+
services.AddControllers()
17+
.AddSimpleJsonOptions();
18+
}
19+
```

src/NET6CustomLibrary/Extensions/DependencyInjection.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,15 @@ public static SwaggerGenOptions AddDateTimeSwaggerGenOptions(this SwaggerGenOpti
9898
return options;
9999
}
100100
#endregion
101+
102+
#region "JSON"
103+
public static IMvcBuilder AddSimpleJsonOptions(this IMvcBuilder builder)
104+
{
105+
builder.AddJsonOptions(options =>
106+
{
107+
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
108+
});
109+
return builder;
110+
}
111+
#endregion
101112
}

0 commit comments

Comments
 (0)