I'm using symfony serializer for my entities and there is no problem unless whenever I try to use groups on my entity properties I get this error :
[Semantical Error] The annotation "@Symfony\Component\Serializer\Annotation\Groups" in property App\Entities\User::$id was never imported. Did you maybe forget to add a "use" statement for this annotation? Here is my entity :
namespace App\Entities; use Doctrine\ORM\Mapping AS ORM; use Symfony\Component\Serializer\Annotation\Groups; /** * @ORM\Entity */ class User { /** * @ORM\Id * @Groups("user_show") * @ORM\Column(type="string") */ protected $id; /** * @ORM\Column(type="string") */ protected $password; } And I have this code in my AppServiceProvider (I'm using Laravel)
public function boot() { $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); $encoders = [new JsonEncoder()]; $normalizers = [new ObjectNormalizer($classMetadataFactory)]; $this->app->bind(SerializerInterface::class, function () use ($normalizers, $encoders) { return new Serializer($normalizers, $encoders); }); }