question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AddNewtonsoftJson and ProblemDetails, .Net Core 3

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
khellangcommented, Apr 7, 2020

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 🤞

1reaction
khellangcommented, Oct 14, 2019

Hi @emilssonn! 👋

Hmm. The AddNewtonsoftJson extension should add a special ProblemDetailsConverter that takes care of wrapping Microsoft.AspNetCore.Mvc.ProblemDetails in a special wrapper type that utilizes the Newtonsoft.Json-specific JsonExtensionData 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 the Microsof.AspNetCore.App FrameworkReference would solve this? @pranavkm?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found