3

After upgrade I'm getting below error in my local :

Exception #0 (InvalidArgumentException): Unable to unserialize value.

#0 myPath/vendor/magento/module-theme/Controller/Result/MessagePlugin.php(157): Magento\Framework\Serialize\Serializer\Json->unserialize('[{\\"type\\":\\"su...')

Tried solutions in below link but none of them helped :(

some solutions here

2
  • Magento 2.2.2 has changed serialize into json format. so we need to do those changes manually . we are also faced same issue while upgrade magento 2.1.4 into magento 2.2.1. we have created category and all manually . Commented Jan 22, 2018 at 8:11
  • Perfect Solution available Here: >Solved: Unserialize Value Magento 2.2.2 Commented Feb 28, 2018 at 6:26

2 Answers 2

0

You can try by adding a line in function unserialize of class Magento\Framework\Serialize\Serializer\Json.

This does happen when magento send some invalid string to parse or add string with multiple slashes to the string.

Even you can check exact error from this json_last_error() method.

So for now add stripslashes at the very first line of method body.

so your function should look like this:

public function unserialize($string)
    {
        $string = stripslashes($string);
        $result = json_decode($string, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \InvalidArgumentException('Unable to unserialize value.');
        }
        return $result;
    }
0

You can fix this issue in the file /vendor/magento/framework/Serialize/Serializer/Json.php, run this command:

public function unserialize($string)
{
    $result = json_decode($string, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
        $result = @unserialize($string);
        if($result){
            return $result;
        }
        throw new \InvalidArgumentException("Unable to unserialize value. Error: " . json_last_error_msg());
    }
    return $result;
}

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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