From 606d8d370da3f6b8d0e0ced6a1d970465ee738a5 Mon Sep 17 00:00:00 2001 From: Emmanuel BORGES Date: Wed, 27 Mar 2019 09:43:12 +0100 Subject: [PATCH] Fix getSetMethodNormalizer to correctly ignore the attributes specified in "ignored_attributes" --- .../Normalizer/GetSetMethodNormalizer.php | 2 +- .../Normalizer/GetSetMethodNormalizerTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index d4be31d3d1c9..7742da7bc082 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -109,7 +109,7 @@ protected function extractAttributes($object, $format = null, array $context = [ $attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3)); - if ($this->isAllowedAttribute($object, $attributeName)) { + if ($this->isAllowedAttribute($object, $attributeName, $format, $context)) { $attributes[] = $attributeName; } } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php index fe56c38ae43f..894801747540 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php @@ -91,6 +91,23 @@ public function testDenormalize() $this->assertTrue($obj->isBaz()); } + public function testIgnoredAttributesInContext() + { + $ignoredAttributes = ['foo', 'bar', 'baz', 'object']; + $this->normalizer->setIgnoredAttributes($ignoredAttributes); + $obj = new GetSetDummy(); + $obj->setFoo('foo'); + $obj->setBar('bar'); + $obj->setCamelCase(true); + $this->assertEquals( + [ + 'fooBar' => 'foobar', + 'camelCase' => true, + ], + $this->normalizer->normalize($obj, 'any') + ); + } + public function testDenormalizeWithObject() { $data = new \stdClass();