Skip to content

[Serializer] Add an @Ignore annotation #28744

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

Merged
merged 1 commit into from
Apr 24, 2020
Merged

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Oct 5, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #24071
License MIT
Doc PR n/a

Add an @Ignore annotation to configure ignored attributes in a convenient way, as well as the related XML and YAML loaders.

TODO:

  • Add tests

@@ -245,6 +245,7 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
$name = $attributeMetadata->getName();

if (
!$attributeMetadata->getIgnore() &&
Copy link
Contributor

@ro0NL ro0NL Oct 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given https://github.com/symfony/symfony/pull/28744/files#diff-7a86113d1484512f310d58e30eadf67dR56 is there any reason to not use $attributeMetadata->ignore here? That would actually implement the advertised perf benefit no?

edit: i see it's about serialization.. but still?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change this, I propose to change this consistently for all attributes in another PR.

Copy link
Contributor

@GuilhemN GuilhemN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love your work on improving this component 💪

@Koc
Copy link
Contributor

Koc commented Oct 6, 2018

What about providing @ExclusionPolicy in JMS-serializer manner? There is opened PR #19374 for that.

@fbourigault
Copy link
Contributor

The plans to improve the Serializer are in #19374 (comment).

@fabpot
Copy link
Member

fabpot commented Mar 20, 2019

@dunglas Do you plan to finish this PR before 4.3 feature freeze?

@dunglas
Copy link
Member Author

dunglas commented Mar 20, 2019

Yes I'll try to finish it tomorrow

@joelwurtz
Copy link
Contributor

Can this annotation be a PropertyInfo component feature instead ? Which remove the property from the getProperties method if needed ?

So other components / library can profit from this metadata as well ?

@fbourigault
Copy link
Contributor

IMHO, the @ignore annotation should be owned by the Serializer component because we may want to exclude the property for the Serializer but to include it for anything else.

And about properties extraction, after trying to finish #28775, I figured that the interface about extracting properties to (un-)serialize must belong to the Serializer component and we could also ship a default implementation built on top of the PropertyInfo component.

Then, we could use decorators, to implement @Ignore, @ExclusionPolicy, @Expose, @Since, @Until, etc... We also be able to move the @Groups into an implementation of this interface.

This would move the logic of getting which properties must be (un-)serialize out of Normalizer and improve a lot the S.O.L.I.D.ity of the Serializer component and help to deprecate the GetSetMethodNormalizer, the PropertyNormalizer, the AbstractObjectNormalizer and the AbstractNormalizer.

@joelwurtz, @dunglas let's talk about this at Symfony Live :)

@joelwurtz
Copy link
Contributor

👍 for talking about this at SymfonyLive, as for the annotation, i don't see a problem on having it on Serializer only by using a dedicated PropertyInfo extractor chain ?

A lot of the annotations that you propose can be also useful in the context of the Automapper if this component is wanted, i would prefer having those in the symfony property info component as decorator, so other components can also profit of this.

Also if this gets merged #30704 and there is a direct link between PropertyAccess and ProperyInfo component in the future, those annotation + decorators could be used in many place where we want to restrict property. Like in the Form / Validator / Workflow compoenent, this would allow to restrict some properties to be used when using a property path, and avoid exposing some data.

but let's discuss this at symfony live like you said,

Copy link
Contributor

@dmaicher dmaicher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could try to finalize this one within the EUFOSSA hackathon if I get some feedback 😊

@joelwurtz
Copy link
Contributor

Just talk with @dmaicher and i think it would be wise to do/finish #30818 (or at least the basics) first before doing this. WDYT @dunglas ?

@raress96
Copy link

raress96 commented Jan 3, 2020

Any updates regarding this?

@dunglas dunglas force-pushed the ignore-annot branch 2 times, most recently from 90b2874 to 383ea22 Compare January 15, 2020 17:57
@dunglas
Copy link
Member Author

dunglas commented Jan 15, 2020

Tests added and comments resolved. This PR should be good to be merged now.
As the refactoring work on the Serializer is stuck for months (#30818), I propose to move forward regarding this PR, we'll be able to refactor this later anyway if needed.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one wording question

@nicolas-grekas
Copy link
Member

(and fixed deps=low)

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally makes sense to me.

@dunglas
Copy link
Member Author

dunglas commented Mar 31, 2020

This one is ready to be merged.

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misses a CHANGELOG entry

@fabpot
Copy link
Member

fabpot commented Apr 24, 2020

Thank you @dunglas.

@fabpot fabpot merged commit 734a006 into symfony:master Apr 24, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
@fabpot fabpot mentioned this pull request May 5, 2020
@vasilvestre
Copy link

Doc issue there symfony/symfony-docs#13585 I am actually tring to add the documentation

javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull request Sep 3, 2020
…lentin, vasilvestre)

This PR was merged into the master branch.

Discussion
----------

[Serializer] Add an @ignore annotation #28744

Complete symfony/symfony#28744

Commits
-------

dcd5b4c Update serializer.rst
56be700 Update serializer.rst
6a3b355 [Serializer] Add an @ignore annotation #28744
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.