Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fcd8e3a

Browse files
committed
[PropertyInfo][Serializer] Fixed extracting ignored properties
1 parent 2cf0686 commit fcd8e3a

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getProperties(string $class, array $context = []): ?array
4747
$serializerClassMetadata = $this->classMetadataFactory->getMetadataFor($class);
4848

4949
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
50-
$ignored = method_exists($serializerClassMetadata, 'isIgnored') && $serializerAttributeMetadata->isIgnored();
50+
$ignored = method_exists($serializerAttributeMetadata, 'isIgnored') && $serializerAttributeMetadata->isIgnored();
5151
if (!$ignored && array_intersect($context['serializer_groups'], $serializerAttributeMetadata->getGroups())) {
5252
$properties[] = $serializerAttributeMetadata->getName();
5353
}

src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,13 @@ public function testGetProperties()
4040
$this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', ['serializer_groups' => ['a']])
4141
);
4242
}
43+
44+
public function testGetPropertiesWithIgnoredProperties()
45+
{
46+
if (!class_exists('Symfony\Component\Serializer\Annotation\Ignore')) {
47+
$this->markTestSkipped('Ignore annotation is not implemented in current symfony/serializer version');
48+
}
49+
50+
$this->assertSame(['visibleProperty'], $this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\IgnorePropertyDummy', ['serializer_groups' => ['a']]));
51+
}
4352
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
13+
14+
use Symfony\Component\Serializer\Annotation\Groups;
15+
use Symfony\Component\Serializer\Annotation\Ignore;
16+
17+
/**
18+
* @author Vadim Borodavko <[email protected]>
19+
*/
20+
class IgnorePropertyDummy
21+
{
22+
/**
23+
* @Groups({"a"})
24+
*/
25+
public $visibleProperty;
26+
27+
/**
28+
* @Groups({"a"})
29+
* @Ignore
30+
*/
31+
private $ignoredProperty;
32+
}

0 commit comments

Comments
 (0)