Skip to content

Commit 4ec0778

Browse files
author
Oleksii Korshenko
authored
MAGETWO-70966: Remove zend json from data object #10306
2 parents 8d0a729 + 8290784 commit 4ec0778

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

lib/internal/Magento/Framework/DataObject.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,21 @@ public function convertToXml(
325325
* Convert object data to JSON
326326
*
327327
* @param array $keys array of required keys
328-
* @return string
328+
* @return bool|string
329+
* @throws \InvalidArgumentException
329330
*/
330331
public function toJson(array $keys = [])
331332
{
332333
$data = $this->toArray($keys);
333-
return \Zend_Json::encode($data);
334+
return \Magento\Framework\Serialize\JsonConverter::convert($data);
334335
}
335336

336337
/**
337338
* The "__" style wrapper for toJson
338339
*
339-
* @param array $keys
340-
* @return string
340+
* @param array $keys
341+
* @return bool|string
342+
* @throws \InvalidArgumentException
341343
*/
342344
public function convertToJson(array $keys = [])
343345
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Serialize;
7+
8+
/**
9+
* This class was introducted only for usage in the \Magento\Framework\DataObject::toJson method.
10+
* It should not be used in other cases and instead \Magento\Framework\Serialize\Serializer\Json::serialize
11+
* should be used.
12+
*/
13+
class JsonConverter
14+
{
15+
/**
16+
* This method should only be used by \Magento\Framework\DataObject::toJson
17+
* All other cases should use \Magento\Framework\Serialize\Serializer\Json::serialize directly
18+
*
19+
* @param string|int|float|bool|array|null $data
20+
* @return bool|string
21+
* @throws \InvalidArgumentException
22+
*/
23+
public static function convert($data)
24+
{
25+
$serializer = new \Magento\Framework\Serialize\Serializer\Json();
26+
return $serializer->serialize($data);
27+
}
28+
}

0 commit comments

Comments
 (0)