Answer the question
In order to leave comments, you need to log in
How to enable JMS\Serializer with required options in symfony by default?
I wrote a simple method in the controller that should return a serialized Event entity that contains related entities and circular references. Connected JMS\Serializer and serialize it like this:
/**
* @Route("/event/{id}", name="event", methods={"GET"})
* @param Event $event
* @param SerializerInterface $serializer
* @return Response
*/
public function getEvent(Event $event, SerializerInterface $serializer): Response
{
return new JsonResponse($serializer->serialize($event, 'json'), 200, [], true);
}
return new JsonResponse($event);
return $this->json($event);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question