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.

Remove (Http)(Validation)ProblemDetails converters

See original GitHub issue

Hi, I think this may be related, but the casing for ProblemDetails is also inconsistent. ProblemDetails itself defaults to camel case, but as you can see above when describing the “Summary” field, it’s capitalized. Shouldn’t that be lower case, assuming @TanvirArjel is using the default naming policy?

I’ve also noticed ProblemDetails does not obey JsonOptions settings, e.g., setting

services.Configure<JsonOptions>(opt =>
{
    opt.JsonSerializerOptions.PropertyNamingPolicy = null; // don't convert to camel case
});

should give a response like

{
    "Type": "https://tools.ietf.org/html/rfc7231#section-6.5.4",
    "Title": "Not Found",
    "Status": 404,
    "Detail": "Account 1 not found.",
    "TraceId": "00-50f63c5d7921484e4797d82687f43033-915b95474bf55ff2-00"
}

but it does not, at least from what I can tell. Maybe this is by design since the spec (https://www.rfc-editor.org/rfc/rfc7807) explicitly lists the properties lower/regular camel case, but it also doesn’t seem to explicitly call out camelcase must be used. I think anyone who is using problem details should be able to use whatever casing their API uses already rather than being forced to either a) have inconsistent casing returned or b) use camel case.

_Originally posted by @jchoca in https://github.com/dotnet/aspnetcore/issues/43261#issuecomment-1248777800_

Repro:: https://github.com/jchoca/ProblemDetailsJsonSettings

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
eiriktsarpaliscommented, Feb 6, 2023

Your example happens to work because you’re prepopulating the dictionary on the property. If I change the POCO to

public class ProblemDetails
{
    [JsonExtensionData]
    [JsonInclude]
    public IDictionary<string, object>? MyProperty { get; } = null;
}

Then your app will immediately hit the exception produced by the source generator.

The function of JsonIgnoreAttribute is to instruct the serializer to bypass accessibility modifiers and try to use private or internal property setters, if available. It predates the source generator and is generally speaking problematic when used in conjunction with it. I would recommend removing it altogether and exposing a property setter that the serializer can readily use.

1reaction
khellangcommented, Dec 13, 2022

IMO, the right thing to do for JsonExtensionData would be to follow PropertyNamingPolicy as the fact that it’s implemented as a .NET dictionary is just an implementation detail. From a JSON POV it’s just a bag of properties. Unfortunately that issue has been shut down due to round-tripping concerns; https://github.com/dotnet/runtime/issues/31167

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom converters for serialization removed - .NET
Learn about the breaking change in ASP.NET Core 8.0 where 'ValidationProblemDetails' and 'ProblemDetails' no longer use custom converters.
Read more >
Disable model validation for single .NET Core API action
NET Core controller declared with the [ApiController] attribute will automatically force validation. I know I can disable this like so in ...
Read more >
Spring Boot Reference Documentation
Try the How-to documents. They provide solutions to the most common questions. Learn the Spring basics. Spring Boot builds on many other Spring...
Read more >
Add error code to ValidationProblemDetails
Constructor of ValidationProblemDetails accepts ModelStateDictionary and we need to convert it to list of ValidationError :.
Read more >
How to Use ModelState Validation in ASP.NET Core Web API
In this article, we are going to talk how to use ModelState validation. Also we are going to see manual and automatic validation....
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