0

I am getting this error in magento 2. Please help me to solve this issue.

1 exception(s): Exception #0 (InvalidArgumentException): Unable to serialize value. Error: - Malformed UTF-8 characters, possibly incorrectly encoded

Exception #0 (InvalidArgumentException): Unable to serialize value. Error: - Malformed UTF-8 characters, possibly incorrectly encoded

0 E:\xampp\htdocs\best4balls\Construction\Code\vendor\magento\framework\App\PageCache\Kernel.php(153): Magento\Framework\Serialize\Serializer\Json->serialize(Array)

1 E:\xampp\htdocs\best4balls\Construction\Code\vendor\magento\module-page-cache\Model\Controller\Result\BuiltinPlugin.php(96): Magento\Framework\App\PageCache\Kernel->process(Object(Magento\Framework\App\Response\Http\Interceptor))

2 E:\xampp\htdocs\best4balls\Construction\Code\vendor\magento\framework\Interception\Interceptor.php(146): Magento\PageCache\Model\Controller\Result\BuiltinPlugin->afterRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Magento\Framework\View\Result\Page\Interceptor), Object(Magento\Framework\App\Response\Http\Interceptor))

strong text

4

1 Answer 1

0

If you are getting this from custom module Please check following answer.

As per Magento 2.2 Release Note

Security enhancements

In general, we’ve removed serialize/unserialize from most the code to improve protection against remote code execution attacks. We’ve enhanced protection of code where use of object serialization or unserialization was unavoidable. Additionally, we’ve increased our use of output escaping to protect against cross-site scripting (XSS) attacks.

So you need to inject \Magento\Framework\Serialize\Serializer\Json class for serialize and unserialize values.

use following code for serialize and unserialize values.

protected $serialize;

public function __construct(
    \Magento\Framework\Serialize\Serializer\Json $serialize
) {
    $this->serialize = $serialize;
}

public function serialize($value){
    return $this->serialize->serialize($value);
}

public function unserialize($value){
    return $this->serialize->unserialize($value);
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.