During building an API service, I encountered with a problem, that I did not want to serve everything as Doctrine Entity object and also, not everything can be converted to json (E.g. Darsyn\IP\Version\Multi)
This issues can be solved by converting one format (used in Doctrine Entity) to wanted format (used in REST API response) We can achieve this via JMS Handlers
To use it you can simply create a Symfony controller
class SalesOrderController extends FOSRestController
{
public function listAction(): Response
{
$allEntities = $this->myRepository->findAll();
// Let's say one entity is holding info about creation date in \DateTime format, but we want to show it as timestamp.
$view = $this->view($allEntities, Response::HTTP_OK);
return $this->handleView($view);
}
}
And then create and register JMS handler (code below)