Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer][Bug] deserialize into pre-existing objects in properties #31208

Closed
@dkarlovi

Description

@dkarlovi

Symfony version(s) affected: 4.2.3

Description

Assuming I have classes like this:

class Inner {
    public $freshInstance = true;
    public $name;
}

class Outer {
    /** @var Inner */
    public $inner;
}

and instance like

$inner = new Inner;
$inner->freshInstance = false;

$outer = new Outer;
$outer->inner = $inner;

When deserializing:

{
    "inner": {"name": "Inner Name"}
}

I'd expect the pre-existing Inner instance to be used, but a new one is created.

How to reproduce

https://github.com/dkarlovi/reproducer-symfony-31208

Possible Solution

Pre-populate OBJECT_TO_POPULATE with the pre-existing object if not-null?

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