I have a Doctrine entity and I use JMS serializer to render it in my API.
I'd like to add a boolean field like this :
/**
* @var bool
*
* @ORM\Column(name = "is_serialized", type = "boolean")
*/
protected $isSerialized = true;
I also use an EventSubscriber to add some data to my entity before serialization.
I'd like to dynamically include or not each entity, based on the $isSerialized
value (I can't modify the Doctrine Query).
class SerializationEventSubscriber extends EventSubscriberInterface
{
/**
* @param ObjectEvent $event
*/
public function onPostSerialize(ObjectEvent $event)
{
if (!$this->isGroup('api', $event)) {
return;
}
$entity = $event->getObject();
$visitor = $event->getVisitor();
if (!$object->isSerialized()) {
// Skip the current object and remove it from serialization
}
}
}
I can't find any information about this, neither in the JMS annotation documentation.