web/lib/Zend/Serializer/Adapter/Json.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Serializer
    16  * @package    Zend_Serializer
    17  * @subpackage Adapter
    17  * @subpackage Adapter
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Json.php 24593 2012-01-05 20:35:02Z matthew $
    20  * @version    $Id$
    21  */
    21  */
    22 
    22 
    23 /** @see Zend_Serializer_Adapter_AdapterAbstract */
    23 /** @see Zend_Serializer_Adapter_AdapterAbstract */
    24 require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
    24 require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
    25 
    25 
    28 
    28 
    29 /**
    29 /**
    30  * @category   Zend
    30  * @category   Zend
    31  * @package    Zend_Serializer
    31  * @package    Zend_Serializer
    32  * @subpackage Adapter
    32  * @subpackage Adapter
    33  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    35  */
    35  */
    36 class Zend_Serializer_Adapter_Json extends Zend_Serializer_Adapter_AdapterAbstract
    36 class Zend_Serializer_Adapter_Json extends Zend_Serializer_Adapter_AdapterAbstract
    37 {
    37 {
    38     /**
    38     /**
    75     {
    75     {
    76         $opts = $opts + $this->_options;
    76         $opts = $opts + $this->_options;
    77 
    77 
    78         try {
    78         try {
    79             $ret = Zend_Json::decode($json, $opts['objectDecodeType']);
    79             $ret = Zend_Json::decode($json, $opts['objectDecodeType']);
       
    80         } catch (Zend_Json_Exception $e) {
       
    81             require_once 'Zend/Serializer/Exception.php';
       
    82             throw new Zend_Serializer_Exception('Invalid json data');
    80         } catch (Exception $e) {
    83         } catch (Exception $e) {
    81             require_once 'Zend/Serializer/Exception.php';
    84             require_once 'Zend/Serializer/Exception.php';
    82             throw new Zend_Serializer_Exception('Unserialization failed by previous error', 0, $e);
    85             throw new Zend_Serializer_Exception('Unserialization failed by previous error', 0, $e);
    83         }
    86         }
    84 
    87 
    85         // json_decode returns null for invalid JSON
       
    86         if ($ret === null && $json !== 'null') {
       
    87             require_once 'Zend/Serializer/Exception.php';
       
    88             throw new Zend_Serializer_Exception('Invalid json data');
       
    89         }
       
    90 
       
    91         return $ret;
    88         return $ret;
    92     }
    89     }
    93 }
    90 }