I am getting data from database model and want to return in json format, but it returns empty array, but when i use dump for variable that contains objects data then it return the actual data.
Here is the code for getting data from object
$user = $this->getUser();
$bookings = $this->getDoctrine()->getRepository(Trip::class)
->findBy(['customer' => $user], ['id' => 'DESC']);
here i return it in json form
return new JsonResponse(['bookings' => $bookings]);
It display on screen that array is empty.
i use dd to check whether data is comming or not
$user = $this->getUser();
$bookings = $this->getDoctrine()->getRepository(Trip::class)
->findBy(['customer' => $user], ['id' => 'DESC']);
dd($bookings);
It returns
kindly help me out how to overcome this issue



You could use symfony component Serializer
You could either turn your array of objects into an array of array:
Or you could directly get a json using the serialize method:
If your entity has circular references, you can look into the documentation to handle it.
One way would be to add a callback method on how to handle objects, but It would be better if you read the documentation because the solution can vary depending on your entity.