protected function castValue($value, $type)
    {
        if (isset($this->scalarMap[$type])) {
            $cast = $this->castToScalar($value, $this->scalarMap[$type]);

            return $cast == $value ? $cast : $value;
        }

        if (is_null($value)) {
            return null;
        }

        if (!is_array($value) && $type === 'array') {
            return (array) $value;
        }

        if (!is_object($value) && $type === 'object') {
            return (object) $value;
        }

        return $this->castToClass($value, $this->resolveNamespace($type));
    }