8000 [Serializer] Fix serialized name with groups · symfony/symfony@4539850 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4539850

Browse files
committed
[Serializer] Fix serialized name with groups
1 parent 64f58cb commit 4539850

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