private static function fromArray($object, $type = null, $innerType = null) {
        if($type == 'array') {
            foreach ($object as $element) {
                // call this method on each element
                $result[]= self::fromArray($element, $innerType);
            }
            
            // return the processed array
            return $result;
        } else if (class_exists($type)) {
            // create the class we are deserializing
            $class = new $type();
            
            // if we can call fromArray on the class call it, otherwise
            // return the object as-is and trigger a warning
            if(is_subclass_of($class, 'AbstractJSONWrapper')) {
                $class->fromArray($object);
                return $class;
            } else {
                trigger_error( __CLASS__ . ": Trying to deserialize " . get_class($class)); 
                return $object;
            }
        } else {
            // if this is not a class, we have nothing to do
            return $object;
        }
    }