10000 fix: GetSetMethodNormalizer::supportss should not check ignored methods · symfony/symfony@858c233 · GitHub
[go: up one dir, main page]

Skip to content

Commit 858c233

Browse files
committed
fix: GetSetMethodNormalizer::supportss should not check ignored methods
1 parent 8b96961 commit 858c233

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

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

Lines changed: 3 additions & 6 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
*
@@ -36,17 +38,11 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
3638
{
3739
private static $setterAccessibleCache = [];
3840

39-
/**
40-
* @param array $context
41-
*/
4241
public function supportsNormalization(mixed $data, string $format = null /* , array $context = [] */): bool
4342
{
4443
return parent::supportsNormalization($data, $format) && $this->supports($data::class);
4544
}
4645

47-
/**
48-
* @param array $context
49-
*/
5046
public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */): bool
5147
{
5248
return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
@@ -82,6 +78,7 @@ private function isGetMethod(\ReflectionMethod $method): bool
8278

8379
return
8480
!$method->isStatic() &&
81+
!$method->getAttributes(Ignore::class) &&
8582
(
8683
((str_starts_with($method->name, 'get') && 3 < $methodLength) ||
8784
(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