@SuppressWarnings("unchecked")
    static <T extends Serializable> T fromString(String value, Class<T> clazz) {
        if (clazz == null) {
            throw new IllegalArgumentException("Non-null value type is required");
        } else if (value == null) {
            value = "";
        }

        T result;
        if (clazz == boolean.class || clazz == Boolean.class) {
            final Boolean boolValue;
            if (value.isEmpty()) {
                boolValue = Boolean.FALSE;
            } else if (value.length() == 1) {
                boolValue = "1".equals(value);
            } else {
                boolValue = Boolean.valueOf(value);
            }
            result = (T) boolValue;
        } else if (byte.class == clazz || Byte.class == clazz) {
            result = (T) (value.isEmpty() ? Byte.valueOf((byte) 0) : Byte.valueOf(value));
        } else if (short.class == clazz || Short.class == clazz) {
            result = (T) (value.isEmpty() ? Short.valueOf((short) 0) : Short.valueOf(value));
        } else if (int.class == clazz || Integer.class == clazz) {
            result = (T) (value.isEmpty() ? Integer.valueOf(0) : Integer.valueOf(value));
        } else if (long.class == clazz || Long.class == clazz) {
            result = (T) (value.isEmpty() ? Long.valueOf(0L) : Long.valueOf(value));
        } else if (float.class == clazz || Float.class == clazz) {
            result = (T) (value.isEmpty() ? Float.valueOf(0F) : Float.valueOf(value));
        } else if (double.class == clazz || Double.class == clazz) {
            result = (T) (value.isEmpty() ? Double.valueOf(0D) : Double.valueOf(value));
        } else if (Enum.class.isAssignableFrom(clazz)) {
            Enum enumValue = null;
            try {
                enumValue = Enum.valueOf((Class<? extends Enum>) clazz, value);
            } catch (IllegalArgumentException exp) {
                for (Enum<?> e : ((Class<? extends Enum>) clazz).getEnumConstants()) {
                    if (e.name().equalsIgnoreCase(value)) {
                        enumValue = e;
                        break;
                    }
                }
            }
            if (enumValue == null) {
                throw new IllegalArgumentException("No enum constant " + clazz.getCanonicalName() + "." + value);
            } else {
                result = (T) enumValue;
            }
        } else if (Map.class.isAssignableFrom(clazz)) { // treat as Map<String, String> & Serializable
            result = (T) toKeyValuePairs(value);
        } else if (TimeZone.class.isAssignableFrom(clazz)) {
            result = (T) TimeZone.getTimeZone(value);
        } else {
            result = clazz.cast(value);
        }
        return result;
    }
Converts given string to a typed value.

@param <T>   type of the value
@param value value in string format
@param clazz non-null class of the value
@return non-null typed value
clickhouse-data/src/main/java/com/clickhouse/config/ClickHouseOption.java