Skip to content

AbstractNormalizer::IGNORED_ATTRIBUTES => does not work with GetSetMethodNormalizer #30453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scottgutman opened this issue Mar 5, 2019 · 0 comments

Comments

@scottgutman
Copy link

scottgutman commented Mar 5, 2019

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 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

@fabpot fabpot closed this as completed Mar 30, 2019
fabpot added a commit that referenced this issue Mar 30, 2019
…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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants