-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
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"]));
});
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