10000 [Serializer] Typed properties Error when denormalizing with deep_object_to_populate true · Issue #52883 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Serializer] Typed properties Error when denormalizing with deep_object_to_populate true #52883
Closed
@f1amy

Description

@f1amy

Symfony version(s) affected

6.3.9

Description

Imagine two classes, both with typed properties and without default values.
First class has an array property of second classes.

Denormalizing into an object with object_to_populate, you could have a case when an array item is being instantiated by the serializer, because it could not be found in the object_to_populate.

In this case with deep_object_to_populate true it will try to read from that freshly instantiated object and fail because typed property is not initialized.

The same case is fixed with normalization: #40578 #41615

How to reproduce

class DataClass
{
    public string $unInitialized;
}

$object = new DataClass();

$normalizer = new ObjectNormalizer();
$normalizer->denormalize(
    ['unInitialized' => 'something'],
    DataClass::class,
    context: [
        'object_to_populate' => $object,
        'deep_object_to_populate' => true,
    ]
);

Possible Solution

Make option skip_uninitialized_values work when denormalizing.

Additional Context

Inspired from comment #40578 (comment)

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