Serialization Symfony return empty array

20 Views Asked by At

I have an error whith Symfony 7.1, when using $this->json in controller with groups i have a serialization error, my success return is empty, object isnt serialized but it's ok when an other part of code with multiple objects. It's very strange.

#[Route('/', methods: ['POST'])]
    public function create(Request $request): JsonResponse
    {
        $appointmentReasonDto = new AppointmentReasonDto();

        $appointmentReasonType = $this->createForm(AppointmentReasonType::class, $appointmentReasonDto);
        $appointmentReasonType->submit($request->request->all());

        if ($appointmentReasonType->isSubmitted() && $appointmentReasonType->isValid()) {
            $appointmentReason = new AppointmentReason();
            $appointmentReason->hydrate($appointmentReasonDto);

            $this->em->persist($appointmentReason);
            $this->em->flush();

            $this->success($appointmentReason, ['appointment-reason:private']);
        }

        return $this->getFormErrorsResponse($appointmentReasonType);
    }

Functionnal code

#[Route('/me', methods: ['GET'])]
    public function getAppointmentReasonsForCurrentUser(): JsonResponse
    {
        /** @var User $user */
        $user = $this->getUser();

        /** @var AppointmentReasonRepository $appointmentReasonRepository */
        $appointmentReasonRepository = $this->em->getRepository(AppointmentReason::class);
        $appointmentReasons = $appointmentReasonRepository->findAllByUser($user);

        return $this->success($appointmentReasons, ['appointment-reason:private']);
    }

I have no idea what caused the bug.

can you help me please ?

Best regards, Jérémy

0

There are 0 best solutions below