Skip to content

[Serializer] ObjectNormalizer recognizes canX as getter, but Attribute loader does not #61021

Open
@themasch

Description

@themasch

Symfony version(s) affected

7.3.1, 7.4

Description

Given a DTO with a canDoCleverThings method, the serializer will normalize this to [ ..., doCleverThings => x ], even if that method has an Ignore attribute, because the ObjectNormalizer supports canX accessors, but the AttributeLoader does not, and therefor does not contribute the ignored flag.

This is different from isX, hasX or getX which work consistently between the two.

How to reproduce

<?php

final readonly class MyData {
  public function __construct(public int $data) {}
  #[Ignore]
  public function canDoCleverThings(): bool {
    return false;
  }
}

Possible Solution

I think adding a |can to the accessorOrMutator regex in AttributeLoader::loadClassMetadata should already solve that.

Additional Context

No response

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