Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddNewtonsoftJson and ProblemDetails using NET 6 #200

Open
wzaieddev opened this issue Sep 21, 2023 · 1 comment
Open

AddNewtonsoftJson and ProblemDetails using NET 6 #200

wzaieddev opened this issue Sep 21, 2023 · 1 comment

Comments

@wzaieddev
Copy link

Hi,
I still having the same problem as (#74 )

I'am having problems using Newtonsoft as the json serializer with problem details.
When this package returns the problem details the Extensions property is serialzied as "Extensions": {...} and not to the parent.

My Web API is built withNET 6
i'm using Hellang.Middleware.ProblemDetails vs 6.5.1

example of response
{
"error": {
"code": "xxxxxxx",
"message": "TEST EXCEPTION"
},
"type": "https://httpstatuses.io/422",
"title": "Bad Request",
"status": 422,
"detail": null,
"instance": "/api/v2/",
"extensions": {
"traceId": "00-c7eeff3ccf1f649acb783983201da96d-b6eab3d064ab8984-00",
"timestamp": "2023-09-21T20:14:36.2960678+02:00"
}
}
when I JSON serializer xx the problem does not arise, and the response is like this

{
"error": {
"code": "xxxxxxx",
"message": "TEST EXCEPTION"
},
"type": "https://httpstatuses.io/422",
"title": "Bad Request",
"status": 422,
"detail": null,
"instance": "/api/v2/",
"traceId": "00-c7eeff3ccf1f649acb783983201da96d-b6eab3d064ab8984-00",
"timestamp": "2023-09-21T20:14:36.2960678+02:00"

}

is there any solution to keep using Newtonsoft ?

@kirodge
Copy link

kirodge commented Oct 5, 2023

I had the same issue when I used the constructor of StatusCodeProblemDetails
var problemDetails = new StatusCodeProblemDetails(StatusCodes.Status409Conflict);

Replacing this with a call to the factory method that returns Mvc.ProblemDetails resolved the issue for me
var problemDetails = StatusCodeProblemDetails.Create(StatusCodes.Status409Conflict);

My guess is that the ProblemDetailsJsonConverter, which is applied through the JsonConverter attribute on Mvc.ProblemDetails, does not apply to the subclass StatusCodeProblemDetails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants