Skip to content

Commit 4c9ca3d

Browse files
multiple JSON configurations
1 parent 7a12819 commit 4c9ca3d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

5_More/Services/GamesApiDotnet6/Program.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99
builder.Services.AddEndpointsApiExplorer();
1010
builder.Services.AddSwaggerGen();
1111

12+
// two different JsonOptions, swagger description uses Microsoft.AspNetCore.Mvc.Json
13+
builder.Services.Configure<Microsoft.AspNetCore.Mvc.JsonOptions>(options =>
14+
{
15+
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
16+
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault;
17+
});
18+
19+
// typed results use Microsoft.AspNetCore.Http.Json
1220
builder.Services.Configure<JsonOptions>(options =>
1321
{
1422
options.SerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault;
15-
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
1623
});
1724

1825
builder.Services.AddSingleton<IGamesRepository, InMemoryGamesRepository>();

0 commit comments

Comments
 (0)