You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
When normalizing an object, some properties are to be ignored.
The method setIgnoredAttributes is deprecated in favor of setting AbstractNormalizer::IGNORED_ATTRIBUTES in the $context array.
However, This only works with ObjectNormalizer and not GetSetMethodNormalizer.
How to reproduce
class testObject {
private $me='me';
private $notMe ='notMe';
public function getMe(): string {return $this->me;}
public function setMe(string $me): void {$this->me = $me;}
public function getNotMe(): string {return $this->notMe;}
public function setNotMe(string $notMe): void {$this->notMe = $notMe;}
}
This does NOT work:
$testObject = new testObject();
$normalizer = new GetSetMethodNormalizer();
$serializer = new Serializer([$normalizer]);
$a1 = $serializer->normalize($testObject, null, [ AbstractNormalizer::IGNORED_ATTRIBUTES => ['notMe'] ] );
dd($a1, $testObject);
This works
$testObject = new testObject();
$normalizer = new ObjectNormalizer();
$serializer = new Serializer([$normalizer]);
$a1 = $serializer->normalize($testObject, null, [AbstractNormalizer::IGNORED_ATTRIBUTES => ['notMe']]);
dd($a1, $testObject);
Possible Solution
Additional context
The text was updated successfully, but these errors were encountered:
…tes specified in "ignored_attributes" (Emmanuel BORGES)
This PR was merged into the 3.4 branch.
Discussion
----------
Fix getSetMethodNormalizer to correctly ignore the attributes specified in "ignored_attributes"
…ed in "ignored_attributes"
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #30453
| License | MIT
The GetSetMethodNormalizer class correctly ignores the attributes specified in "ignored_attributes"
Commits
-------
606d8d3 Fix getSetMethodNormalizer to correctly ignore the attributes specified in "ignored_attributes"
Symfony version(s) affected: 4.2.3
Description
When normalizing an object, some properties are to be ignored.
The method
setIgnoredAttributes
is deprecated in favor of settingAbstractNormalizer::IGNORED_ATTRIBUTES
in the$context
array.However, This only works with
ObjectNormalizer
and notGetSetMethodNormalizer
.How to reproduce
This does NOT work:
This works
Possible Solution
Additional context
The text was updated successfully, but these errors were encountered: