Skip to content

Remove zend json from data object #10306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/internal/Magento/Framework/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down
28 changes: 28 additions & 0 deletions lib/internal/Magento/Framework/Serialize/JsonConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\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
{
/**
* 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
*/
public static function convert($data)
{
$serializer = new \Magento\Framework\Serialize\Serializer\Json();
return $serializer->serialize($data);
}
}