-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add ignored attributes option #24071
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
Comments
Maybe an @ignored annotation like in JMSSerializerBundle could also be added. |
This actually exist through ignored_attributes isn't it ? |
Closing as fixed because of what @vsilvestre-accenture said. Thanks! |
That approach is not a neat way to do it... I would have preferred using an annotation. That way, we can abstract certain implementations and not worry about case to case basis. You guys can take a cue from NewtonSoft.Json. Everything they did is using C# attributes (which is the idea behind PHP Annotations) |
@theoaks in hindsight I agree on this (mind you, this is openened more than two years ago). But yes there is a PR open for this as mentioned. |
This PR was squashed before being merged into the 5.1-dev branch. Discussion ---------- [Serializer] Add an @ignore annotation | Q | A | ------------- | --- | Branch? | master Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #24071 | License | MIT | Doc PR | n/a Add an `@Ignore` annotation to configure [ignored attributes](https://symfony.com/doc/current/components/serializer.html#ignoring-attributes) in a convenient way, as well as the related XML and YAML loaders. TODO: * [x] Add tests Commits ------- 8526d7c [Serializer] Add an @ignore annotation
I know the serializer is due for a redesign (#19330) but I'm daring to make a feature request for the time being. Currently (afaik) the mapping (yaml/xml/annotations) lack a way of ignoring attributes and you end up writing a normalizer to do just that.
With a bit of digging I figured it won't be too difficult to add an attribute metadata option to ignore the attribute (as is done for
groups
andmaxDepth
options). This can then be read by the (to be written)getIgnoredAttributes
getter to get the ignored attributes, instead of accessing theignoredAttributes
array directly.The ignored attribute is useful for classes that have no groups but want to exclude a property, say the
id
property. It's cumbersome to add a group specifically to do that.The YAML could look like this:
Or to keep things clean:
Please share your thoughts as I'm willing to implement this 👍
The text was updated successfully, but these errors were encountered: