public function onPlainResponse(ViewEvent $event) { $request = $event->getRequest(); $response = $event->getResponse(); // No need to perform JSON-RPC serialization here if (!$request instanceof JsonRpcRequestInterface || $request->isNotification()) { return; } // Response is already properly formatted if ($response instanceof JsonRpcResponseInterface) { return; } $response = new JsonRpcResponse($request->getId(), json_decode($this->serializer->serialize($event->getResponse(), 'json', $this->createSerializerContext($event)))); $event->setResponse($response); }