-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Support conditional exclude for classes #1099
Conversation
Very nice addition! Thanks a lot! |
Hi Asmir, Cool, thanks! 👍 The PR definitely still needs some work, but since I only used this library yesterday for the first time, I'm not sure how to do the missing parts, especiallcy the unit tests. Regards, Arne |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I found some time to review this.
The base-intuition is good and I think you are on the right direction.
The other drivers (xml and yaml) are still missing and tests.
For tests a good starting point can be:
public function testExpressionExclusionConfiguredWithDisjunctStrategy() public function testExpressionExclusion($person, ExpressionFunction $function, $json)
You can probably add a property of PersonSecret
that is an object and uses class based exclusion rules.
Hi @goetas , i was working on this again and run into a issue. While serialization works fine, there is one problem during deserialization. /**
* @Serializer\Exclude(if="object.expired != true")
*/
class PersonAccount {
/**
* @Serializer\Type("string")
*/
public $name;
/**
* @Serializer\Type("boolean")
*/
public $expired;
} During deserialize() we come to the point where the exclude-If expression is being evaluated. Unfortunately the object is null, since the deserialization has not happened yet and therefore the expression fails. I see two options.
What is your opinion on this? Thanks! |
This is a known issue, and |
That would be the easiest solution. For my use case that would be perfectly fine, since I'm interested in serialization only anyway. For the library I don't know, should deserialization offer the same functionality like serialization? If this is ok for you, it's fine for me. |
Ok, hope I got this right and in sync now. I've tried to get it working with the solution you have suggested before, but I wasn't able to completely skip the relevant objects during deserialization. If an object was skipped by a class level exclude-if, the array of the parent element still contained a null item. For now I've removed the Exclude-If on deserialization, it only works during serialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better! We'll done.
Can you please add some tests for the Metadata in xml and yaml?
* Added tests for the drivers * Misc
Done (and now the drivers are actually working). 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Can you please fix the code style issue (you can just run vendor/bin/phpcbf), after that I think it is ready to be merged!
It is coming from GraphNavigatorTest, which I didn't change. phpcbf does not find anything on my installation ("No fixable errors were found") Tried to change this part manually, let's see what travis says... still strange. |
Thanks a lot for your excellent work! very very nice! :) |
Hi Asmir, |
Hi,
after further checking #1098, I've noticed that this functionality just isn't there yet. I've created a first draft PR for supporting condtional excludes on class level.
The PR includes the changes in class metadata and SerializationGraphNavigator as well as the annotation driver.
Still missing is:
While all existing tests are passing, I was not able to add the corresponding unit tests for this case. I'm also not sure if there are any unintended side effects by not completely excluding the class if there is an @exclude annotation like it is done at the moment, but keeping it and do the evaluation during serialization.
Thanks for your help!