public function cast($array)
    {
        if (!is_array($array)) {
            throw new \InvalidArgumentException(sprintf('Expected an array, but got %s!', gettype($array)));
        }
        foreach ($array as $key => $value) {
            //is this a repeating array?
            $mapKey = $this->mapKey($key);
            //try to cast the value
            try {
                $array[$key] = $this[$mapKey]->cast($value);
            } catch (KeyNotFoundException $knfex) {
                //no key, no typecast, nothing happened.
            } catch (\InvalidArgumentException $iaex) {
                //unexpected value
                throw new \InvalidArgumentException(
                    sprintf(
                        'Unexpected value for key %s: %s',
                        $key,
                        $iaex->getMessage()
                    ),
                    0,
                    $iaex
                );
            }
        }
        return $array;
    }