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

[Breaking change]: ValidationProblemDetails and ProblemDetails no longer use custom converters #504

Open
1 of 3 tasks
captainsafia opened this issue Apr 10, 2023 · 0 comments
Labels
8.0.0 Announcement Breaking change Documented The breaking change has been published to the .NET Core docs

Comments

@captainsafia
Copy link

Description

Prior to .NET 8 Preview 2, ValidationProblemDetails and ProblemDetails type used custom converters to support JSON serialization due to a lack of support for the IgnoreNullValues option. Now that this option is supported by the S.T.J APIs, we've removed the custom converters in the framework in favor of the serialization provided by the framework.

As a result of this, the properties in the ValidationProblemDetails and ProblemDetails types no longer indiscriminately assume lowercase type names. Developers must specific a JsonNamingPolicy to get the correct behavior.

Version

.NET 8 Preview 2

Previous behavior

string content = "{\"status\":400,\"detail\":\"HTTP egress is not enabled.\"}";
using MemoryStream stream = new();
using StreamWriter writer = new(stream);
writer.Write(content);
writer.Flush();
stream.Position = 0;

JsonSerializerOptions options = new();
options.Converters.Add(new JsonStringEnumConverter());

ValidationProblemDetails? details = await JsonSerializer.DeserializeAsync<ValidationProblemDetails>(stream, options);
Console.WriteLine(details.Status); // 400

New behavior

string content = "{\"status\":400,\"detail\":\"HTTP egress is not enabled.\"}";
using MemoryStream stream = new();
using StreamWriter writer = new(stream);
writer.Write(content);
writer.Flush();
stream.Position = 0;

JsonSerializerOptions options = new();
options.Converters.Add(new JsonStringEnumConverter());

ValidationProblemDetails? details = await JsonSerializer.DeserializeAsync<ValidationProblemDetails>(stream, options);
Console.WriteLine(details.Status); // null

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

Now that IgnoreNullValues is supported by the S.T.J APIs, we've removed the custom converters in the framework in favor of the serialization provided by the framework.

Recommended action

Provide a JSON serializer options with the correct details.

JsonSerializerOptions options = new()
{
   PropertyNameCaseInsensitive = true
};
ValidationProblemDetails? details = await JsonSerializer.DeserializeAsync<ValidationProblemDetails>(stream, options);

Affected APIs

@aspnet aspnet locked as resolved and limited conversation to collaborators Apr 10, 2023
@captainsafia captainsafia changed the title [Breaking change]: ValidationProblemDetails and ProblemDetails no longer use custom converetrs [Breaking change]: ValidationProblemDetails and ProblemDetails no longer use custom converters Apr 11, 2023
@gewarren gewarren added the Documented The breaking change has been published to the .NET Core docs label May 5, 2023
@guardrex guardrex added the 8.0.0 label Nov 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
8.0.0 Announcement Breaking change Documented The breaking change has been published to the .NET Core docs
Projects
None yet
Development

No branches or pull requests

3 participants