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

ConditionalExpose/Exclude annotation does not work on class level #1098

Closed
arneee opened this issue Jun 20, 2019 · 2 comments
Closed

ConditionalExpose/Exclude annotation does not work on class level #1098

arneee opened this issue Jun 20, 2019 · 2 comments

Comments

@arneee
Copy link
Contributor

arneee commented Jun 20, 2019

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Hi,

I have an array with several Office Objects. When serializing, I would like to exclude some if these objects, based on dynamic conditions. The documentation shows how to do that with @exclude and the annoation field if.

While it works for normal properties, the dynamic part (if) of @exclude does not seem to be used when applied to a class.

Steps required to reproduce the problem

/**
 * Office
 *
 * @Exclude(if="false")
 */
class Office {
   public $id = 1;
}
$array = [new Office(), new Office()];
$serializer->serialize($array , 'json');

Expected Result

  • All office objects are included in the serialized result, since the exclude condition evalues to false

Actual Result

[
{},
{}
]
  • No office objects are serialized, since the condition seems not be be evaluated.

I've also triedit with a real world example (isGranted provided by the Symfony bundle), but the isGranted method is never called. There is also no exception when using an invalid method, for example @Exclude(if="noSuchMethod('view',object)") which makes me believe that the condition is not even parsed.

@arneee
Copy link
Contributor Author

arneee commented Jun 21, 2019

Hi,

this functionality does not seem to exist, I've created a draft PR. #1099

@arneee
Copy link
Contributor Author

arneee commented Apr 19, 2020

Possible now with #1099

@arneee arneee closed this as completed Apr 19, 2020
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

2 participants