From e8f9b352e1a3f0afa44a2f821858b0b6ed261f4d Mon Sep 17 00:00:00 2001 From: dmanners Date: Tue, 18 Jul 2017 15:49:19 +0000 Subject: [PATCH 1/2] Replay the static call to Zend_Json with a static call to Magento JsonConverter. - This is only in place for this one use case and should not be used for other times with converting json --- lib/internal/Magento/Framework/DataObject.php | 10 +++++--- .../Framework/Serialize/JsonConverter.php | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 lib/internal/Magento/Framework/Serialize/JsonConverter.php diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index 547a23ed979d1..a6ebc50fe98bc 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -325,19 +325,21 @@ public function convertToXml( * Convert object data to JSON * * @param array $keys array of required keys - * @return string + * @return bool|string + * @throws \InvalidArgumentException */ public function toJson(array $keys = []) { $data = $this->toArray($keys); - return \Zend_Json::encode($data); + return \Magento\Framework\Serialize\JsonConverter::convert($data); } /** * The "__" style wrapper for toJson * - * @param array $keys - * @return string + * @param array $keys + * @return bool|string + * @throws \InvalidArgumentException */ public function convertToJson(array $keys = []) { diff --git a/lib/internal/Magento/Framework/Serialize/JsonConverter.php b/lib/internal/Magento/Framework/Serialize/JsonConverter.php new file mode 100644 index 0000000000000..b9b72cad10d2a --- /dev/null +++ b/lib/internal/Magento/Framework/Serialize/JsonConverter.php @@ -0,0 +1,25 @@ +serialize($data); + } +} From 7ab108a9c0a2ca0d34df25186baf6beb5f0607ea Mon Sep 17 00:00:00 2001 From: dmanners Date: Mon, 24 Jul 2017 13:50:20 +0000 Subject: [PATCH 2/2] Update the class and method comment to highlight that this should only be used in a single case --- .../Magento/Framework/Serialize/JsonConverter.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Serialize/JsonConverter.php b/lib/internal/Magento/Framework/Serialize/JsonConverter.php index b9b72cad10d2a..6f6fdfb249408 100644 --- a/lib/internal/Magento/Framework/Serialize/JsonConverter.php +++ b/lib/internal/Magento/Framework/Serialize/JsonConverter.php @@ -6,14 +6,17 @@ namespace Magento\Framework\Serialize; /** - * Used to convert \Magento\Framework\DataObject to Json - * - * @deprecated @see \Magento\Framework\Serialize\Serializer\Json::serialize + * This class was introducted only for usage in the \Magento\Framework\DataObject::toJson method. + * It should not be used in other cases and instead \Magento\Framework\Serialize\Serializer\Json::serialize + * should be used. */ class JsonConverter { /** - * @param $data + * This method should only be used by \Magento\Framework\DataObject::toJson + * All other cases should use \Magento\Framework\Serialize\Serializer\Json::serialize directly + * + * @param string|int|float|bool|array|null $data * @return bool|string * @throws \InvalidArgumentException */