Skip to content

Version v5.4.24 of symfony/property-info broke ArrayDenormalizer #50675

Closed
@Moghul

Description

@Moghul

Symfony version(s) affected

v5.4.24

Description

I have an array with numeric keys to denormalize, and the property the data will be assigned to is a Doctrine ArrayCollection. Previous to this release denormalization worked fine, but now this denormalization exception is collected:

Symfony\Component\Serializer\Exception\NotNormalizableValueException object
 currentType => string "int" (3)
 expectedTypes => array(1)
   integer 0 => string "string" (6)
 path => string "[0].answerOptions[0]" (20)
 useMessageForUser => true
 message => string "The type of the key "0" must be "string" ("int" given)." (55)
 code => integer 0
 file => string "path/to/symfony/serializer/Exception/NotNormalizableValueException.php" (98)
 line => integer 31

The exception is thrown in the ArrayDenormalizer class in line 58.

How to reproduce

I can see that the ArrayDenormalizerTest class doesn't test arrays with numeric keys or no specified keys at all, so that might be the place to start.

The PhpDocExtractor does seem to extract both int and string correctly from the property but because they are passed individually to the ArrayDenormalizer, it fails when $context['key_type'] is 'string'.

Possible Solution

The right solution is probably to update the type check in the ArrayDenormalizer class to check all possible types rather than just the key_type value.

Additional Context

No response

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