public function cast($object)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException(sprintf('Expected an object, but got %s!', gettype($object)));
        }
        foreach ($this->map as $name => $type) {
            if (isset($object->{$name})) {
                try {
                    $object->{$name} = $type->cast($object->{$name});
                } catch (\InvalidArgumentException $iaex) {
                    //unexpected value
                    throw new \InvalidArgumentException(
                        sprintf(
                            'Unexpected value for property %s: %s',
                            $name,
                            $iaex->getMessage()
                        ),
                        0,
                        $iaex
                    );
                }
            }
        }
        return $object;
    }