@SuppressWarnings("unchecked")
    static <T> T stringToType(String str, Class<T> clazz) {
        try {
            Function<String, ?> func = supportedElementTypes.get(clazz);
            if (func == null) {
                func = convertExternalTypes.get(clazz);
            }
            if (func != null) {
                return (T) func.apply(str);
            }
        } catch (NumberFormatException e) {
            throw e;
        } catch (Throwable cause) {
            throw new IllegalArgumentException(
                    "Can't convert '" + str + "' to type '" + clazz.getSimpleName() + "'.", cause);
        }

        throw new IllegalArgumentException(
                "Can't convert '" + str + "' to type '" + clazz.getSimpleName() + "'.");
    }
Converts the given {@code str} to {@code T} type object. e.g., "42" -> 42.

@throws IllegalArgumentException if {@code str} can't be deserialized to {@code T} type object.
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedServiceTypeUtil.java