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

Skip to content

[Serializer] #[Ignore] on method ignores properties with same name #46918

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
ostrolucky opened this issue Jul 12, 2022 · 15 comments
Closed

[Serializer] #[Ignore] on method ignores properties with same name #46918

ostrolucky opened this issue Jul 12, 2022 · 15 comments

Comments

@ostrolucky
Copy link
Contributor

ostrolucky commented Jul 12, 2022

Symfony version(s) affected

6.2.2

Description

Serializer does not differentiate between properties and methods when applying #[Ignore] attributes/annotations

How to reproduce

class IgnoreDummy
{
    public $name;

    #[Ignore]
    public function getName()
    {
        return 'foo';
    }
}
public function testLoadIgnore()
{
    $classMetadata = new ClassMetadata(IgnoreDummy::class);
    $this->loader->loadClassMetadata($classMetadata);

    $this->assertFalse($classMetadata->getAttributesMetadata()['name']->isIgnored());
}

Possible Solution

Serializer metadata should group methods and public properties to separate "buckets"

Additional Context

No response

@ostrolucky ostrolucky added the Bug label Jul 12, 2022
@OskarStark OskarStark changed the title [Serializer] #[Ignore] on method ignores properties with same name [Serializer] #[Ignore] on method ignores properties with same name Jul 14, 2022
@chalasr
Copy link
Member

chalasr commented Jul 15, 2022

Symfony version(s) affected
6.2.2

I'm jealous :)

ping @dunglas

@xabbuh
Copy link
Member

xabbuh commented Jul 19, 2022

maybe this can be addressed together with #46592

@ostrolucky
Copy link
Contributor Author

Indeed. Let's close this as duplicate

@ostrolucky
Copy link
Contributor Author

Looks like chosen solution for #46592 won't work here, so I need to reopen

@ostrolucky ostrolucky reopened this Jul 19, 2022
@guilliamxavier
Copy link
Contributor

Besides Ignore, isn't that the same for other attributes/annotations? and even serialization in general?

@ostrolucky
Copy link
Contributor Author

ostrolucky commented Jul 20, 2022

Yeah of course, here this looks to be a design issue of sf serializer, that there is no namespacing that would differentiate if annotation/attribute/whatever is on attribute, method or wherever else.

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@ostrolucky
Copy link
Contributor Author

This issue is still relevant

@carsonbot carsonbot removed the Stalled label Mar 16, 2023
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@ostrolucky
Copy link
Contributor Author

This issue is still relevant

@carsonbot carsonbot removed the Stalled label Sep 17, 2023
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

@jarbey
Copy link

jarbey commented Aug 6, 2024

I agree on this bug, specially when you have class with a property and a isPropertyName method

Workaround is to rename the isPropertyName to something else, but code is less readable.

To me #Ignore on method should not apply on public attribute

class IgnoreDummy
{
public $name;

#[Ignore]
public function isName()
{
    return 'foo';
}

}

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

6 participants