Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Typed properties Error when denormalizing with deep_object_to_populate true #52883

Copy link
Copy link
Closed
@f1amy

Description

@f1amy
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.