-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add an annotation to exclude properties from serialization #34373
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
FYI: Related to #19374 (A massive PR that actually adds this feature) |
A good way to exclude fields is to use the annotation Group. See documentation here: https://symfony.com/doc/current/serializer.html#using-serialization-groups-annotations Is there any problem with this feature or should this issue be closed? |
Closing here for now. Please leave a comment if the suggested groups do not solve your use case. |
The idea was I wanted to designate fields as not serializable by default (as in, not in the Default group). Groups are a nice feature, but if I go that way, I have to tag all the other properties of the object (and probably its relations) with a specific group, which seems like a huge overkill when you just want to exclude a couple fields from default serialization. |
Thank you for this suggestion. |
Friendly reminder that this issue exists. If I don't hear anything I'll close this. |
I've added the "help wanted" label because I find this feature really useful. |
@derrabus I think the https://symfony.com/blog/new-in-symfony-5-1-serializer-improvements#added-ignore-annotation |
Oh, indeed! Let‘s close this issue then! |
Looks like same is achievable with attribute: https://symfony.com/doc/current/components/serializer.html#ignoring-attributes |
Description
I think it would make sense to be able to designate certain properties/methods of a class as never serializable/unserializable.
Example
In my particular case, I have a couple of bitmap properties which I expose via boolean setters/getters for each bit, as well as properties for current and new password. I would never want these properties serialized, even when otherwise serializing all properties of the object.
@Exclude
(that's what JMS calls their counterpart) or@Ignore
annotation would help such case.The text was updated successfully, but these errors were encountered: