decoder = $decoder; $this->_appState = $appState; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** * Parse Request body into array of params. * * @param string $encodedBody Posted content from request. * @return array|null Return NULL if content is invalid. * @throws \InvalidArgumentException * @throws \Magento\Framework\Webapi\Exception If decoding error was encountered. */ public function deserialize($encodedBody) { if (!is_string($encodedBody)) { throw new \InvalidArgumentException( sprintf('"%s" data type is invalid. String is expected.', gettype($encodedBody)) ); } try { $decodedBody = $this->serializer->unserialize($encodedBody); } catch (\InvalidArgumentException $e) { if ($this->_appState->getMode() !== State::MODE_DEVELOPER) { throw new \Magento\Framework\Webapi\Exception(new Phrase('Decoding error.')); } else { throw new \Magento\Framework\Webapi\Exception( new Phrase( 'Decoding error: %1%2%3%4', [PHP_EOL, $e->getMessage(), PHP_EOL, $e->getTraceAsString()] ) ); } } return $decodedBody; } }