Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

System.Text.Json is unable to deserialize FluentValidation.Results.ValidationResult #1928

Copy link
Copy link
@Arclight3

Description

@Arclight3
Issue body actions

FluentValidation version

10.4.0

ASP.NET version

6.0.202

Summary

System.Text.Json is unable to deserialize FluentValidation.Results.ValidationResult, while Newtonsoft.Json is able to do it.

I filled an issue on dotnet runtime repo (dotnet/runtime#68280) but they suggested to open one here because it might be that FluentValidation relies on conventions not supported by System.Text.Json or that it implements a converter only for Json.NET.

Steps to Reproduce

Check this code in .NET 6:

var validationResult = new ValidationResult
{
    Errors = { new ValidationFailure("MyProperty", "Invalid MyProperty") }
};

// System.Text.Json
var serialized = JsonSerializer.Serialize(validationResult);
var deserialized = JsonSerializer.Deserialize<ValidationResult>(serialized);

// Newtonsoft.Json
var serialized2 = JsonConvert.SerializeObject(validationResult, Formatting.Indented);
var deserialized2 = JsonConvert.DeserializeObject<ValidationResult>(serialized2);

The deserialized variable contains a ValidationResult object with IsValid = true, and 0 Errors.
The deserialized2 variable contains a ValidationResult object with IsValid = false, and 1 Error.

The serialization operation produces an identical json string for both libraries, but the System.Text.Json fails to deserialize it back to a ValidationResult object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.