too long

I want to get attributes that have a serialization group and the group name.

i.e : I want to get bus_write from this attribute of my entity.

/**
     * @var ArrayCollection<Driver> The driver of this bus.
     * @ORM\ManyToMany(targetEntity="Driver", mappedBy="bus",cascade={"persist","remove","merge"})
     * @ORM\JoinColumn(name="DRIVER_id", referencedColumnName="id")
     * @Groups({"bus_write"})
     */
    private $driver;

This one should do the trick:

$reader = $this->container->get('annotation_reader');
$refClass = new \ReflectionClass('AppBundle\Entity\Bus');
$refProp = $refClass->getProperty('driver');
$annotations = $reader->getPropertyAnnotations($refProp);

// Find the Groups annotation
foreach ($annotations as $annot) {
    if ($annot instanceof \JMS\Serializer\Annotation\Groups) {
        $groups = $annot->groups;
        break;
    }
}

dump($groups); // array:1 [0 => 'bus_write']