You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHP automatically converts numeric strings used as array keys to integers for optimization purposes.
Therefore, scenario below is not supported.
As symfony "normalizes" <string|int, \DummyInner> to simple \DummyInner[] and takes first type only at
Fatal error: Uncaught Symfony\Component\Serializer\Exception\NotNormalizableValueException: The type of the key "str" must be "string" ("int" given). in symfony-serializer-demo/vendor/symfony/serializer/Exception/NotNormalizableValueException.php on line 31
Symfony version(s) affected
6.2.12
Description
Hi!
PHP automatically converts numeric strings used as array keys to integers for optimization purposes.
Therefore, scenario below is not supported.
As symfony "normalizes"
<string|int, \DummyInner>
to simple\DummyInner[]
and takes first type only athttps://github.com/symfony/serializer/blob/6.3/Normalizer/AbstractObjectNormalizer.php#L502-L508
The exception message looks like
How to reproduce
Possible Solution
Since the union types aren't supported yet (and we don't know when and if) maybe we could have a workaround for this ?
Not sure if this is the right place for workaround, but at least it works on my scenario
https://github.com/symfony/serializer/blob/6.3/Normalizer/ArrayDenormalizer.php#L47-L75
and we can add "auto-conversion" like
The text was updated successfully, but these errors were encountered: