AddNewtonsoftJson and ProblemDetails, .Net Core 3
See original GitHub issueI am having problems using Newtonsoft as the json serializer (using AddNewtonsoftJson
in startup) with problem details.
When this package returns the problem details the Extensions
property is serialzied as "Extensions": {...}
and not to the parent.
If I in a controller use return Problem(detail: "test");
the Extensions
property is serialized correctly.
The Microsoft.AspNetCore.Mvc.ProblemDetails
has a JsonExtensionDataAttribute
on the property, but since it is .Net Core 3.0 it is in the namespace System.Text.Json.Serialization
.
This issue might not be specific for this package but I need to start somewhere.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
NET Core 3 preview 4: 'AddNewtonsoftJson' is not defined
NET Core 3 preview 4, the "API" template for a F# ASP.NET MVC project fails to build. This is without any changes to...
Read more >Format response data in ASP.NET Core Web API
ASP.NET Core MVC supports formatting response data, using specified formats or in response to a client's request. Format-specific Action Results.
Read more >What's new in ASP.NET Core 7.0
The problem details service implements the IProblemDetailsService interface, which supports creating Problem Details for HTTP APIs. For more ...
Read more >Using Newtonsoft.Json In .NET Core 3+ Projects
Recently I've been working a lot in .NET Core 3.0 and 3.1 projects. Both upgrading existing 2.2 projects and a couple of new...
Read more >Using the ProblemDetails Class in ASP.NET Core Web API
ProblemDetails class in ASP.NET Core Web APIs helps us to standardize our error handling and have better communication with API clients.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve pushed a new version, v5.0, to NuGet, where I’ve removed all internal usage of custom sub-types in the middleware. Hopefully this means that the built-in converters should wrap the instances in
AnnotatedProblemDetails
and make Newtonsoft.Json pick up the attributes 🤞Hi @emilssonn! 👋
Hmm. The
AddNewtonsoftJson
extension should add a specialProblemDetailsConverter
that takes care of wrappingMicrosoft.AspNetCore.Mvc.ProblemDetails
in a special wrapper type that utilizes the Newtonsoft.Json-specificJsonExtensionData
attribute. See https://github.com/aspnet/AspNetCore/blob/c565386a3ed135560bc2e9017aa54a950b4e35dd/src/Mvc/Mvc.NewtonsoftJson/src/ProblemDetailsConverter.cs#L45 and https://github.com/aspnet/AspNetCore/blob/c565386a3ed135560bc2e9017aa54a950b4e35dd/src/Mvc/Mvc.NewtonsoftJson/src/AnnotatedProblemDetails.cs.I wonder what’s going wrong here. Maybe releasing a version targeting
netcoreapp3.0
and theMicrosof.AspNetCore.App
FrameworkReference
would solve this? @pranavkm?