diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index c3b9f06d45726..234e64e79c8a2 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Serializer\Normalizer; +use Symfony\Component\Serializer\Annotation\Ignore as LegacyIgnore; use Symfony\Component\Serializer\Attribute\Ignore; /** @@ -97,7 +98,7 @@ private function supports(string $class): bool private function isGetMethod(\ReflectionMethod $method): bool { return !$method->isStatic() - && !$method->getAttributes(Ignore::class) + && !($method->getAttributes(Ignore::class) || $method->getAttributes(LegacyIgnore::class)) && !$method->getNumberOfRequiredParameters() && ((2 < ($methodLength = \strlen($method->name)) && str_starts_with($method->name, 'is')) || (3 < $methodLength && (str_starts_with($method->name, 'has') || str_starts_with($method->name, 'get'))) diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/ClassWithIgnoreAnnotation.php b/src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/ClassWithIgnoreAnnotation.php new file mode 100644 index 0000000000000..22df4f84a3cbb --- /dev/null +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/ClassWithIgnoreAnnotation.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Serializer\Tests\Fixtures\Attributes; + +use Symfony\Component\Serializer\Annotation\Ignore; + +class ClassWithIgnoreAnnotation +{ + public string $foo; + + #[Ignore] + public function isSomeIgnoredMethod(): bool + { + return true; + } +} diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php index 7877a3c5e17e1..e3e8873799e45 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php @@ -30,6 +30,7 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; +use Symfony\Component\Serializer\Tests\Fixtures\Attributes\ClassWithIgnoreAnnotation; use Symfony\Component\Serializer\Tests\Fixtures\Attributes\ClassWithIgnoreAttribute; use Symfony\Component\Serializer\Tests\Fixtures\Attributes\GroupDummy; use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy; @@ -427,9 +428,22 @@ public function testNoStaticGetSetSupport() $this->assertFalse($this->normalizer->supportsNormalization(new ObjectWithJustStaticSetterDummy())); } - public function testNotIgnoredMethodSupport() + /** + * @param class-string $class + * + * @dataProvider provideNotIgnoredMethodSupport + */ + public function testNotIgnoredMethodSupport(string $class) { - $this->assertFalse($this->normalizer->supportsNormalization(new ClassWithIgnoreAttribute())); + $this->assertFalse($this->normalizer->supportsNormalization(new $class())); + } + + public static function provideNotIgnoredMethodSupport(): iterable + { + return [ + [ClassWithIgnoreAttribute::class], + [ClassWithIgnoreAnnotation::class], + ]; } public function testPrivateSetter()