-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #50933 [Serializer] Fix deserializing nested arrays of objects wi…
…th mixed keys (HypeMC) This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] Fix deserializing nested arrays of objects with mixed keys | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #50675 | License | MIT | Doc PR | - Currently an error is thrown when trying to deserialize the following nested array of objects: ```php use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; $serializer = new Serializer([ new ObjectNormalizer(null, null, null, new PhpDocExtractor()), new ArrayDenormalizer(), ], ['json' => new JsonEncoder()]); class Outer { /** * `@var` array<int|string, Inner> */ public array $inners; } class Inner { public string $name; } $serializer->deserialize('{"inners": {"1": {"name": "One"}, "two": {"name": "Two"}}}', Outer::class, 'json'); ``` ``` Fatal error: Uncaught Symfony\Component\Serializer\Exception\NotNormalizableValueException: The type of the key "two" must be "int" ("string" given). ``` The same happens when using generics, e.g. `ArrayCollection<Inner>`. Commits ------- db0e89383c [Serializer] Fix deserializing nested arrays of objects with mixed keys
- Loading branch information
Showing
4 changed files
with
90 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters