protected function cast($input, SplObjectStorage $list)
    {
        $value = $input instanceof JsonSerializable
            ? $input->jsonSerialize()
            : $input;

        if ($value instanceof DateTimeInterface) {
            $value = $value->format(DateTime::ISO8601);
        }

        if (is_iterable($value)) {
            $value = i\iterable_to_array($value, true);
        }

        if (is_array($value) || $value instanceof stdClass) {
            $value = $this->castRecursive($input, $value, $list);
        }

        return $value;
    }