diff --git a/lib/internal/Magento/Framework/Controller/Result/Json.php b/lib/internal/Magento/Framework/Controller/Result/Json.php index 3349d4507577b..ddb7ca533df39 100644 --- a/lib/internal/Magento/Framework/Controller/Result/Json.php +++ b/lib/internal/Magento/Framework/Controller/Result/Json.php @@ -28,12 +28,21 @@ class Json extends AbstractResult */ protected $json; + /** + * @var \Magento\Framework\Serialize\Serializer\Json + */ + private $serializer; + /** * @param \Magento\Framework\Translate\InlineInterface $translateInline */ - public function __construct(InlineInterface $translateInline) - { + public function __construct( + InlineInterface $translateInline, + \Magento\Framework\Serialize\Serializer\Json $serializer = null + ) { $this->translateInline = $translateInline; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** @@ -43,10 +52,14 @@ public function __construct(InlineInterface $translateInline) * @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 = []) { - $this->json = \Zend_Json::encode($data, $cycleCheck, $options); + if ($data instanceof \Magento\Framework\DataObject) { + $data = $data->toArray(); + } + $this->json = $this->serializer->serialize($data); return $this; }