10000 Recursive denormalization does not support object_to_populate · Issue #21669 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Recursive denormalization does not support object_to_populate #21669
Closed
@davidbarratt

Description

@davidbarratt
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:

  1. Populating the existing name object
  2. Any 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:

  1. Run the denormalizer with the type hinted class as the type.
  2. Pass the same groups from the parent to the child
  3. Attempt to get the value of the property, if a value is returned, it should use that value in object_to_populate (assuming object_to_populate was set on the parent)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0