Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
rimas-kudelis opened this issue Nov 14, 2019 · 10 comments
Closed

Comments

@rimas-kudelis
Copy link

rimas-kudelis commented Nov 14, 2019

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.

@Nyholm
Copy link
Member

Nyholm commented Nov 17, 2019

FYI: Related to #19374 (A massive PR that actually adds this feature)
One could pick out some good from that PR to implement this feature.

@Nek-
Copy link
Contributor

Nek- commented Oct 22, 2020

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?

@xabbuh
Copy link
Member

xabbuh commented Oct 28, 2020

Closing here for now. Please leave a comment if the suggested groups do not solve your use case.

@xabbuh xabbuh closed this as completed Oct 28, 2020
@rimas-kudelis
Copy link
Author

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.

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@carsonbot
Copy link

Friendly reminder that this issue exists. If I don't hear anything I'll close this.

@derrabus derrabus added Keep open Help wanted Issues and PRs which are looking for volunteers to complete them. and removed Stalled labels May 16, 2021
@derrabus
Copy link
Member

I've added the "help wanted" label because I find this feature really useful.

@maxhelias
Copy link
Contributor

maxhelias commented May 16, 2021

@derrabus I think the @Ignore attribute introduced in 5.1 should be enough.

https://symfony.com/blog/new-in-symfony-5-1-serializer-improvements#added-ignore-annotation

@derrabus
Copy link
Member

Oh, indeed! Let‘s close this issue then!

@derrabus derrabus removed Help wanted Issues and PRs which are looking for volunteers to complete them. Keep open labels May 16, 2021
@darius-v
Copy link

@derrabus I think the @Ignore attribute introduced in 5.1 should be enough.

https://symfony.com/blog/new-in-symfony-5-1-serializer-improvements#added-ignore-annotation

Looks like same is achievable with attribute: https://symfony.com/doc/current/components/serializer.html#ignoring-attributes

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

8 participants