Skip to content

ProblemDetailsWriter ignores custom json converters when serializing problem details. #64244

@voroninp

Description

@voroninp

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

There's an article about a change in behavior. However, it's not clear whether some custom converters were removed, or the converters as a concept not working anymore.

Anyway, I've looked at the source code and made some debugging and I see that DefaultProblemDetailsWriter receives JsonSerializerOptions which does not contain our custom converters:

builder.AddJsonOptions(options => {
            options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
            options.JsonSerializerOptions.Converters.Add(new MoneyEuroOnlyConverter());
            options.JsonSerializerOptions.Converters.Add(new ParsableJsonStringConverter<OrderReference>());
            options.JsonSerializerOptions.Converters.Add(new TypedValueJsonConverter(factoryMethodNames: ["New", "GetByKey"]));
        });
Image Image

Expected Behavior

I expect custom json covnerters to be used when serializing problem details.

Steps To Reproduce

ProblemDetailsWriterDoesNotUseCustomCovnerters.zip

Here's a simple solution to reproduce the issue in .NET 10.

Just a note:
If I use ProblemDetailsService directly from foo controller, ProblemDetails value is serialized using custom converters, that is it works as expected.
It looks like there's some interference with the exception handling middleware.

Exceptions (if any)

No response

.NET Version

8.0.414

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-problem-details

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions