Skip to content
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

Exclude based on condition #422

Closed
websirnik opened this issue Oct 14, 2014 · 2 comments
Closed

Exclude based on condition #422

websirnik opened this issue Oct 14, 2014 · 2 comments

Comments

@websirnik
Copy link

What is the right approach to exclude certain objects being serialized based on condition.
For example, when I serializing User, User has both pubic and private Posts. In a public context, I don't want private posts to be exposed. How should I prevent private posts from serialization?

I need to do something like the following. I know that the usage of @Exclude is not right, but just to illustrate the point.

class User
{
    /**
     *
     * @JMS\Groups({"user"})
     * @JMS\Exclude({"privacy.type":"private"})
     * @JMS\Type("array<Org\AppBundle\Document\Post>")
     * @MongoDB\ReferenceMany(targetDocument="Org\AppBundle\Document\Post")
     */
    protected $posts;
@stof
Copy link
Contributor

stof commented Dec 17, 2014

You could register your own exclusion policy in the serializer to achieve such exclusion

@goetas
Copy link
Collaborator

goetas commented Jan 20, 2017

solved with schmittjoh/serializer#673

@goetas goetas closed this as completed Jan 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants