Closed
Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | no |
Symfony version | 3.3.0 |
It would be really helpful if there was a way to recursively deseriailize objects.
Given an object like this:
class User
{
/**
* Set Name.
*
* @param Name $name
*/
public function setName(Name $name) : self
{
$this->name = $name;
return $this;
}
}
The serializer throws a Symfony\Component\Serializer\Exception\UnexpectedValueException
with the message "Expected argument of type 'Name', 'array' given" because it passes an array into setName()
rather than running the denormilization on the Name
class and then passing the result into setName()
. I think having this feature would be really helpful. I could of course allow this method to accept Name and array, but then it will bypass:
Populating the existing name objectAny groups that may be used for access.
Since the method already has a typehint of the only thing it will accept (a class) I think it makes sense that if a non-scalar type hint is encountered in a setter, it should:
Run the denormalizer with the type hinted class as the type.Pass the same groups from the parent to the child- Attempt to get the value of the property, if a value is returned, it should use that value in
object_to_populate
(assumingobject_to_populate
was set on the parent)