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

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
f1amy opened this issue Dec 4, 2023 · 0 comments · Fixed by #53140
Closed

Comments

@f1amy
Copy link

f1amy commented Dec 4, 2023

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)

@f1amy f1amy added the Bug label Dec 4, 2023
nicolas-grekas added a commit that referenced this issue Dec 29, 2023
…t_to_populate (mtarld)

This PR was merged into the 5.4 branch.

Discussion
----------

[Serializer] Skip uninitialized properties with deep_object_to_populate

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #52883
| License       | MIT

Commits
-------

79c39c1 [Serializer] Skip uninitialized properties with deep_object_to_populate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants