3

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); }); } 

1 Answer 1

2

Solved the problem by registering symfony annotations for laravel doctrine More info here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.