Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Serializer] Fix deserializing nested arrays of objects with mixed keys#50933
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
ed46804 to3ff1be8Compare
nicolas-grekas left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can you check the follow patch please?
diff --git a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.phpindex 05d8b79d1a..dfd023a437 100644--- a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php+++ b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php@@ -49,9 +49,7 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Denormaliz $type = substr($type, 0, -2);- $builtinTypes = array_map(static function (Type $keyType) {- return $keyType->getBuiltinType();- }, \is_array($keyType = $context['key_type'] ?? []) ? $keyType : [$keyType]);+ $builtinTypes = array_map(static function ($keyType) { return $keyType->getBuiltinType(); }, (array) ($context['key_type'] ?? [])); foreach ($data as $key => $value) { $subContext = $context;@@ -109,20 +107,12 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Denormaliz */ private function validateKeyType(array $builtinTypes, $key, string $path): void { if (!$builtinTypes) { return; }- $unexpectedDataType = true; foreach ($builtinTypes as $builtinType) { if (('is_'.$builtinType)($key)) {- $unexpectedDataType = false;- break;+ return; } }- if ($unexpectedDataType) {- throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, implode('", "', $builtinTypes), get_debug_type($key)), $key, $builtinTypes, $path, true);- }+ throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, implode('", "', $builtinTypes), get_debug_type($key)), $key, $builtinTypes, $path, true); } }diff --git a/src/Symfony/Component/Serializer/composer.json b/src/Symfony/Component/Serializer/composer.jsonindex 1b9537f8f8..11e67a8a7e 100644--- a/src/Symfony/Component/Serializer/composer.json+++ b/src/Symfony/Component/Serializer/composer.json@@ -34,7 +34,7 @@ "symfony/http-kernel": "^4.4|^5.0|^6.0", "symfony/mime": "^4.4|^5.0|^6.0", "symfony/property-access": "^5.4|^6.0",- "symfony/property-info": "^5.4.24|^6.0",+ "symfony/property-info": "^5.4.24|^6.2.11", "symfony/uid": "^5.3|^6.0", "symfony/validator": "^4.4|^5.0|^6.0", "symfony/var-dumper": "^4.4|^5.0|^6.0",@@ -47,7 +47,7 @@ "phpdocumentor/type-resolver": "<1.4.0", "symfony/dependency-injection": "<4.4", "symfony/property-access": "<5.4",- "symfony/property-info": "<5.4.24",+ "symfony/property-info": "<5.4.24|>=6,<6.2.11", "symfony/uid": "<5.3", "symfony/yaml": "<4.4" },
Uh oh!
There was an error while loading.Please reload this page.
HypeMC commentedJul 27, 2023
@nicolas-grekas The following part won't work: - $builtinTypes = array_map(static function (Type $keyType) {- return $keyType->getBuiltinType();- }, \is_array($keyType = $context['key_type'] ?? []) ? $keyType : [$keyType]);+ $builtinTypes = array_map(static function ($keyType) { return $keyType->getBuiltinType(); }, (array) ($context['key_type'] ?? []));
|
3ff1be8 todb0e893Comparenicolas-grekas commentedJul 27, 2023
Thank you@HypeMC. |
Currently an error is thrown when trying to deserialize the following nested array of objects:
The same happens when using generics, e.g.
ArrayCollection<Inner>.