Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 606d8d3

Browse files
author
Emmanuel BORGES
committed
Fix getSetMethodNormalizer to correctly ignore the attributes specified in "ignored_attributes"
1 parent 860884a commit 606d8d3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected function extractAttributes($object, $format = null, array $context = [
109109

110110
$attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3));
111111

112-
if ($this->isAllowedAttribute($object, $attributeName)) {
112+
if ($this->isAllowedAttribute($object, $attributeName, $format, $context)) {
113113
$attributes[] = $attributeName;
114114
}
115115
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ public function testDenormalize()
9191
$this->assertTrue($obj->isBaz());
9292
}
9393

94+
public function testIgnoredAttributesInContext()
95+
{
96+
$ignoredAttributes = ['foo', 'bar', 'baz', 'object'];
97+
$this->normalizer->setIgnoredAttributes($ignoredAttributes);
98+
$obj = new GetSetDummy();
99+
$obj->setFoo('foo');
100+
$obj->setBar('bar');
101+
$obj->setCamelCase(true);
102+
$this->assertEquals(
103+
[
104+
'fooBar' => 'foobar',
105+
'camelCase' => true,
106+
],
107+
$this->normalizer->normalize($obj, 'any')
108+
);
109+
}
110+
94111
public function testDenormalizeWithObject()
95112
{
96113
$data = new \stdClass();

0 commit comments

Comments
 (0)