8000 bug #51456 [Serializer] Fix serialized name with groups during denorm… · symfony/symfony@e4ada73 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4ada73

Browse files
bug #51456 [Serializer] Fix serialized name with groups during denormalization (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
2 parents ee534ea + 4539850 commit e4ada73

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,14 @@ private function getCacheValueForAttributesMetadata(string $class, array $contex
127127
throw new LogicException(sprintf('Found SerializedName and SerializedPath annotations on property "%s" of class "%s".', $name, $class));
128128
}
129129

130-
$groups = $metadata->getGroups();
131-
if (!$groups && ($context[AbstractNormalizer::GROUPS] ?? [])) {
130+
$metadataGroups = $metadata->getGroups();
131+
$contextGroups = (array) ($context[AbstractNormalizer::GROUPS] ?? []);
132+
133+
if ($contextGroups && !$metadataGroups) {
132134
continue;
133135
}
134-
if ($groups && !array_intersect($groups, (array) ($context[AbstractNormalizer::GROUPS] ?? []))) {
136+
137+
if ($metadataGroups && !array_intersect($metadataGroups, $contextGroups) && !\in_array('*', $contextGroups, true)) {
135138
continue;
136139
}
137140

src/Symfony/Component/Serializer/Tests/NameConverter/MetadataAwareNameConverterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public static function attributeAndContextProvider()
149149
['buzForExport', 'buz', ['groups' => 'b']],
150150
['buz', 'buz', ['groups' => ['c']]],
151151
['buz', 'buz', []],
152+
['buzForExport', 'buz', ['groups' => ['*']]],
152153
];
153154
}
154155

0 commit comments

Comments
 (0)
0