serializer = $serializer; $this->contentTypeJson(); } public function responseClass($class) { $this->responseClass = $class; } public function call($method, $url, $payload = '') { $payload = $this->serialize($payload); $response = parent::call($method, $url, $payload); $response->setBody($this->deserialize($response)); return $response; } private function serialize($payload) { try { return empty($payload) ? $payload : $this->serializer->serialize($payload, 'json'); } catch (RuntimeException $e) { throw new PCurlException(sprintf('Unable to serialize payload - %s : %s', $e->getMessage(), $payload)); } } private function deserialize($response) { try { return $this->responseClass ? $this->serializer->deserialize($response, $this->responseClass, 'json') : $response; } catch (RuntimeException $e) { var_dump($response); throw new PCurlException(sprintf('Unable to deserialize response - %s : %s', $e->getMessage(), $response)); } } }