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();