Skip to content

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

@skylargutman

Description

@skylargutman

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy