Skip to content
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

Exclude annotation does not work as documented for private or protected properties #891

Open
ianef opened this issue May 11, 2022 · 0 comments

Comments

@ianef
Copy link

ianef commented May 11, 2022

| Bug report? | yes

According to the documentation in the exclusion strategies following should work:
http://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies#dynamic-exclusion-strategy

    /**
     * @Exclude(if="null")
     */
    private ?string $name;

It doesn't, it fails with an exception stating that a boolean was expected but found null.

If you try and use the private or protected property that also fails with access rights issues:

    /**
     * @Exclude(if="id==null")
     */

You can use the 'object' as a reference to call a getter method which works for serialisation as follows:

    /**
     * @Exclude(if="object.getName()==null")
     */

But this then fails when de-serialising because the 'object' does not yet exist at decision time. You can overcome it by adding a direction test but this is getting somewhat ridiculous and not at all a nice and straightforward to exclude a property.

    /**
     * @Serialize\Exclude(if="context.getDirection() === constant('JMS\\Serializer\\GraphNavigatorInterface::DIRECTION_SERIALIZATION') && object.getName()==null")
     */

I'm using jms/serializer-bundle 4.0.2
Symfony 3.4.49 (yes I know, it's currently being upgraded!)
PHP 7.4.27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant