Skip to content

Symfony validator does not honour (or at least collect info for) #SerializedName #60497

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

Open
redbullmarky opened this issue May 21, 2025 · 2 comments

Comments

@redbullmarky
Copy link

redbullmarky commented May 21, 2025

Symfony version(s) affected

6.4

Description

#56962 appears to reference the same/similar issue however it's closed as completed. The validator does not collect any information about the #SerializedName, limiting the validator's usefulness when dealing with any kind of renamed fields.

How to reproduce

Essentially, if you had a property set up as such:

	#[SerializedName('display_name')]
	#[Assert\NotBlank()]
	public string $displayName;

The validator, on failing, does not have any details that allow you to meaningfully respond to whatever "client" you might have. You'll get an error relating to displayName and, whilst this is not incorrect, it's not hugely useful.
Generally speaking, the value specified in #[SerializedName] is the external name. Perhaps the one relating to the API field, or the input field's name.

Possible Solution

Possible solutions:

  1. acknowledge the SerializedName by gathering it into another property, or perhaps:
  2. provide a method for fetching an object that relates to the property - metadata or reflection instance or whatever - so that these things can be extracted.

Additional Context

No response

@yceruto
Copy link
Member

yceruto commented May 21, 2025

Since SerializedName is not currently supported in the validation process, it seems more like a feature request than a bug.

@yceruto
Copy link
Member

yceruto commented May 21, 2025

Maybe it's something to improve in ConstraintViolationListNormalizer from the serializer component.

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

No branches or pull requests

3 participants