I\'ve an entity I usually serialize using the JMS Serializer bundle. I have to add to the serialization some fields that doesn\'t reside in the entity itself but are gathere
To further answer the original question. Here is how you limit added data for some serialized groups (in this example some_data is only added when we are not using the list group:
public function onPostSerializeSomeEntityJson(ObjectEvent $event) {
$entity = $event->getObject();
if (!in_array('list', (array)$event->getContext()->attributes->get('groups'))) {
$event->getVisitor()->addData('user_access', array(
'some_data' => 'some_value'
));
}
}
(array)$event->getContext()->attributes->get('groups') contains an array of the used serialized groups.