Closed
Description
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)