Any one tell me how i can overwrite this file in magento 2.3
Path:
Magento2\lib\internal\Magento\Framework\Webapi\Rest\Response\Renderer\Json.php
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityJust Create di.xml under app/code/vendor/Module/etc and put below code
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="\Magento\Framework\Webapi\Rest\Response\Renderer\Json" type="Vendor\Module\Webapi\Rest\Response\Renderer\Json" />
</config>
Find below the code which is working just need to put file name no need of extension of file.
Follow Below Steps:
Overwrite this file:
\Magento\Framework\Webapi\Rest\Response\Renderer\Json.php
We are overwrite Json.php file using : di.xml (under app/code/Bhashkar/Module/etc and put below code)
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="\Magento\Framework\Webapi\Rest\Response\Renderer\Json" type="Bhashkar\Module\Webapi\Rest\Response\Renderer\Json" />
</config>
Create Bhashkar\Webapi\Webapi\Rest\Response\Renderer\Json.php File and modify the functionality as per your Requirement :
namespace Bhashkar\Module\Webapi\Rest\Response\Renderer;
class Json implements \Magento\Framework\Webapi\Rest\Response\RendererInterface
{
/**
* Adapter mime type.
*/
const MIME_TYPE = 'application/json';
/**
* @var \Magento\Framework\Json\Encoder
*/
protected $encoder;
/**
* Initialize dependencies.
*
* @param \Magento\Framework\Json\Encoder $encoder
*/
public function __construct(\Magento\Framework\Json\Encoder $encoder)
{
$this->encoder= $encoder;
}
/**
* Convert data to JSON.
*
* @param object|array|int|string|bool|float|null $data
* @return string
*/
public function render($data)
{
return $this->encoder->encode($data);
}
/**
* Get JSON renderer MIME type.
*
* @return string
*/
public function getMimeType()
{
return self::MIME_TYPE;
}
}