8000 [Serializer] Add special '*' serialization group that allows any group · symfony/symfony@54e24a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 54e24a8

Browse files
nrobinaubertinfabpot
authored andcommitted
[Serializer] Add special '*' serialization group that allows any group
1 parent 704c648 commit 54e24a8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ protected function getAllowedAttributes($classOrObject, array $context, bool $at
250250
// If you update this check, update accordingly the one in Symfony\Component\PropertyInfo\Extractor\SerializerExtractor::getProperties()
251251
if (
252252
!$ignore &&
253-
(false === $groups || array_intersect($attributeMetadata->getGroups(), $groups)) &&
253+
(false === $groups || array_intersect(array_merge($attributeMetadata->getGroups(), ['*']), $groups)) &&
254254
$this->isAllowedAttribute($classOrObject, $name = $attributeMetadata->getName(), null, $context)
255255
) {
256256
$allowedAttributes[] = $attributesAsString ? $name : $attributeMetadata;

src/Symfony/Component/Serializer/Tests/Norm 8000 alizer/AbstractNormalizerTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function testGetAllowedAttributesAsString()
7272

7373
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['other']], true);
7474
$this->assertEquals(['a3', 'a4'], $result);
75+
76+
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['*']], true);
77+
$this->assertEquals(['a1', 'a2', 'a3', 'a4'], $result);
7578
}
7679

7780
public function testGetAllowedAttributesAsObjects()
@@ -104,6 +107,9 @@ public function testGetAllowedAttributesAsObjects()
104107

105108
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['other']], false);
106109
$this->assertEquals([$a3, $a4], $result);
110+
111+
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['*']], false);
112+
$this->assertEquals([$a1, $a2, $a3, $a4], $result);
107113
}
108114

109115
public function testObjectWithStaticConstructor()

0 commit comments

Comments
 (0)
0