protected function castObject($value): array
    {
        if ($value instanceof Traversable && (!isset($this->traversable) || !is_a($value, $this->traversable, true))) {
            return iterator_to_array($value);
        }

        if ($value instanceof stdClass) {
            return call_user_func('get_object_vars', $value);
        }

        return [$value];
    }