Skip to content

Commit

Permalink
bug #51456 [Serializer] Fix serialized name with groups during denorm…
Browse files Browse the repository at this point in the history
…alization (mtarld)

This PR was merged into the 6.3 branch.

Discussion
----------

[Serializer] Fix serialized name with groups during denormalization

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #51238
| License       | MIT
| Doc PR        |

Commits
-------

4539850 [Serializer] Fix serialized name with groups
  • Loading branch information
nicolas-grekas committed Aug 23, 2023
2 parents ee534ea + 4539850 commit e4ada73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ private function getCacheValueForAttributesMetadata(string $class, array $contex
throw new LogicException(sprintf('Found SerializedName and SerializedPath annotations on property "%s" of class "%s".', $name, $class));
}

$groups = $metadata->getGroups();
if (!$groups && ($context[AbstractNormalizer::GROUPS] ?? [])) {
$metadataGroups = $metadata->getGroups();
$contextGroups = (array) ($context[AbstractNormalizer::GROUPS] ?? []);

if ($contextGroups && !$metadataGroups) {
continue;
}
if ($groups && !array_intersect($groups, (array) ($context[AbstractNormalizer::GROUPS] ?? []))) {

if ($metadataGroups && !array_intersect($metadataGroups, $contextGroups) && !\in_array('*', $contextGroups, true)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public static function attributeAndContextProvider()
['buzForExport', 'buz', ['groups' => 'b']],
['buz', 'buz', ['groups' => ['c']]],
['buz', 'buz', []],
['buzForExport', 'buz', ['groups' => ['*']]],
];
}

Expand Down

0 comments on commit e4ada73

Please sign in to comment.