8000 fix: GetSetMethodNormalizer::supportss should not check ignored methods · symfony/symfony@3ca371b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ca371b

Browse files
nikophilnicolas-grekas
authored andcommitted
fix: GetSetMethodNormalizer::supportss should not check ignored methods
1 parent 6ab60c4 commit 3ca371b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Serializer\Normalizer;
1313

14+
use Symfony\Component\Serializer\Annotation\Ignore;
15+
1416
/**
1517
* Converts between objects with getter and setter methods and arrays.
1618
*
@@ -85,6 +87,7 @@ private function isGetMethod(\ReflectionMethod $method): bool
8587

8688
return
8789
!$method->isStatic() &&
90+
!$method->getAttributes(Ignore::class) &&
8891
(
8992
((str_starts_with($method->name, 'get') && 3 < $methodLength) ||
9093
(str_starts_with($method->name, 'is') && 2 < $methodLength) ||

src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1717
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1818
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
19+
use Symfony\Component\Serializer\Annotation\Ignore;
1920
use Symfony\Component\Serializer\Exception\LogicException;
2021
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
2122
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
@@ -430,6 +431,11 @@ public function testNoStaticGetSetSupport()
430431
$this->assertFalse($this->normalizer->supportsNormalization(new ObjectWithJustStaticSetterDummy()));
431432
}
432433

434+
public function testNotIgnoredMethodSupport()
435+
{
436+
$this->assertFalse($this->normalizer->supportsNormalization(new ClassWithIgnoreAttribute()));
437+
}
438+
433439
public function testPrivateSetter()
434440
{
435441
$obj = $this->normalizer->denormalize(['foo' => 'foobar'], ObjectWithPrivateSetterDummy::class);
@@ -753,3 +759,14 @@ public function __call($key, $value)
753759
throw new \RuntimeException('__call should not be called. Called with: '.$key);
754760
}
755761
}
762+
763+
class ClassWithIgnoreAttribute
764+
{
765+
public string $foo;
766+
767+
#[Ignore]
768+
public function isSomeIgnoredMethod(): bool
769+
{
770+
return true;
771+
}
772+
}

0 commit comments

Comments
 (0)
0