Answer the question
In order to leave comments, you need to log in
How to validate the data included in the object during deserialization in Symfony?
I have a User object and an array with keys corresponding to the field names of the User object.
With the help of annotations, the User object has created restrictions on the accepted values (constraints), I want to use the Symfony serialization component to deserialize the data directly into the object and validate them at the same time, for example, so that when passing a string to the field of the DateTime object, the validator returns an error about the wrong type, not PHP.
Deserialization code example:
$serializer->deserialize($request->getContent(), User::class, "json", [
"object_to_populate" => $user,
"groups" => "registration"
]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question