Skip to content

Respect JsonSerializerOptions in validation errors #62341

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
…a/valid-jsonoptions
  • Loading branch information
captainsafia committed Jun 16, 2025
commit 4517667cda063fcb1f14a4f787865f9222e60b69
2 changes: 1 addition & 1 deletion src/Validation/src/ValidatableTypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public virtual async Task ValidateAsync(object? value, ValidateContext context,
var key = string.IsNullOrEmpty(originalPrefix) ?
formattedMemberName :
$"{originalPrefix}.{formattedMemberName}";
context.AddOrExtendValidationError(key, validationResult.ErrorMessage);
context.AddOrExtendValidationError(memberName, key, validationResult.ErrorMessage, value);
}

if (!validationResult.MemberNames.Any())
Expand Down
7 changes: 6 additions & 1 deletion src/Validation/src/ValidateContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ internal JsonSerializerOptions? SerializerOptions
return serializerProp.GetValue(jsonOptions) as JsonSerializerOptions;
}

internal void AddValidationError(string key, string[] error)
/// <summary>
/// Optional event raised when a validation error is reported.
/// </summary>
public event Action<ValidationErrorContext>? OnValidationError;

internal void AddValidationError(string propertyName, string key, string[] error, object? container)
{
ValidationErrors ??= [];
ValidationErrors[key] = error;
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.