{"action":"created","issue":{"url":"https://api.github.com/repos/schmittjoh/JMSSerializerBundle/issues/264","labels_url":"https://api.github.com/repos/schmittjoh/JMSSerializerBundle/issues/264/labels{/name}","comments_url":"https://api.github.com/repos/schmittjoh/JMSSerializerBundle/issues/264/comments","events_url":"https://api.github.com/repos/schmittjoh/JMSSerializerBundle/issues/264/events","html_url":"https://github.com/schmittjoh/JMSSerializerBundle/issues/264","id":10091474,"number":264,"title":"Detecting serializion groups in the serialize listeners","user":{"login":"pulse00","id":185278,"avatar_url":"https://avatars.githubusercontent.com/u/185278?v=3","gravatar_id":"","url":"https://api.github.com/users/pulse00","html_url":"https://github.com/pulse00","followers_url":"https://api.github.com/users/pulse00/followers","following_url":"https://api.github.com/users/pulse00/following{/other_user}","gists_url":"https://api.github.com/users/pulse00/gists{/gist_id}","starred_url":"https://api.github.com/users/pulse00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulse00/subscriptions","organizations_url":"https://api.github.com/users/pulse00/orgs","repos_url":"https://api.github.com/users/pulse00/repos","events_url":"https://api.github.com/users/pulse00/events{/privacy}","received_events_url":"https://api.github.com/users/pulse00/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2013-01-18T08:51:38Z","updated_at":"2015-03-06T11:59:12Z","closed_at":"2015-03-06T11:59:12Z","body":"When adding additional attributes in serialization listeners, is there a way to detect the active serialization groups?"},"comment":{"url":"https://api.github.com/repos/schmittjoh/JMSSerializerBundle/issues/comments/77548578","html_url":"https://github.com/schmittjoh/JMSSerializerBundle/issues/264#issuecomment-77548578","issue_url":"https://api.github.com/repos/schmittjoh/JMSSerializerBundle/issues/264","id":77548578,"user":{"login":"pulse00","id":185278,"avatar_url":"https://avatars.githubusercontent.com/u/185278?v=3","gravatar_id":"","url":"https://api.github.com/users/pulse00","html_url":"https://github.com/pulse00","followers_url":"https://api.github.com/users/pulse00/followers","following_url":"https://api.github.com/users/pulse00/following{/other_user}","gists_url":"https://api.github.com/users/pulse00/gists{/gist_id}","starred_url":"https://api.github.com/users/pulse00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulse00/subscriptions","organizations_url":"https://api.github.com/users/pulse00/orgs","repos_url":"https://api.github.com/users/pulse00/repos","events_url":"https://api.github.com/users/pulse00/events{/privacy}","received_events_url":"https://api.github.com/users/pulse00/received_events","type":"User","site_admin":false},"created_at":"2015-03-06T11:59:12Z","updated_at":"2015-03-06T11:59:12Z","body":"@Sander-Toonen thanks for the feedback. i've come up with this helper in my serializers:\r\n\r\n```php\r\n\r\n/**\r\n * @param SerializationContext $context\r\n * @param $group\r\n * @return bool\r\n */\r\nprivate function isGroupActive(SerializationContext $context, $group)\r\n{\r\n    return $this->areGroupsActive($context, [$group]);\r\n}\r\n\r\n/**\r\n * @param SerializationContext $context\r\n * @param array $serializationGroups\r\n * @return bool\r\n */\r\nprivate function areGroupsActive(SerializationContext $context, array $serializationGroups)\r\n{\r\n    /** @var Some $groupContext */\r\n    $groupContext = $context->attributes->get('groups');\r\n\r\n    if ($groupContext->isDefined()) {\r\n        $groups = $groupContext->get();\r\n\r\n        if (is_array($groups)) {\r\n            foreach ($serializationGroups as $group) {\r\n                if (in_array($group, $groups)) {\r\n                    return true;\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    return false;\r\n}\r\n```"}}