translateInline = $translateInline; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** * Set json data * * @param mixed $data * @param boolean $cycleCheck Optional; whether or not to check for object recursion; off by default * @param array $options Additional options used during encoding * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function setData($data, $cycleCheck = false, $options = []) { if ($data instanceof \Magento\Framework\DataObject) { $data = $data->toArray(); } $this->json = $this->serializer->serialize($data); return $this; } /** * @param string $jsonData * @return $this */ public function setJsonData($jsonData) { $this->json = (string)$jsonData; return $this; } /** * {@inheritdoc} */ protected function render(HttpResponseInterface $response) { $this->translateInline->processResponseBody($this->json, true); $response->setHeader('Content-Type', 'application/json', true); $response->setBody($this->json); return $this; } }