Skip to content

Commit

Permalink
Restore previous serializer behaviour
Browse files Browse the repository at this point in the history
Use the approved workaround for the changes to JSON source generation and runtime serialization.
  • Loading branch information
martincostello committed Aug 19, 2022
1 parent 2479622 commit b43a46c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/API/ApiBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.IO.Compression;
using System.Net.Mime;
using System.Text.Json.Serialization.Metadata;
using MartinCostello.Api.Extensions;
using MartinCostello.Api.Options;
using Microsoft.AspNetCore.CookiePolicy;
Expand Down Expand Up @@ -79,7 +80,9 @@ public static WebApplication Configure(WebApplicationBuilder builder)
{
options.SerializerOptions.PropertyNameCaseInsensitive = false;
options.SerializerOptions.WriteIndented = true;
options.SerializerOptions.AddContext<ApplicationJsonSerializerContext>();
options.SerializerOptions.TypeInfoResolver = JsonTypeInfoResolver.Combine(
ApplicationJsonSerializerContext.Default,
new DefaultJsonTypeInfoResolver());
});

builder.Services.AddResponseCompression((options) =>
Expand Down
3 changes: 1 addition & 2 deletions src/API/Swagger/ExampleFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ internal sealed class ExampleFilter : IOperationFilter, IParameterFilter, ISchem
/// <param name="options">The <see cref="JsonOptions"/> to use.</param>
public ExampleFilter(IOptions<JsonOptions> options)
{
_options = new(options.Value.SerializerOptions);
_options.TypeInfoResolver = null; // Remove the JsonSerializerContext
_options = options.Value.SerializerOptions;
}

/// <inheritdoc />
Expand Down

0 comments on commit b43a46c

Please sign in to comment.