code: @SuppressWarnings("PMD.LooseCoupling")
      public static Object castValue(Method m, Class<?> castType, String value) {
  
          try {
              if (castType.isEnum()) {
                  Method valueOf;
                  try {
                      valueOf = castType.getMethod("valueOf", String.class);
                      return valueOf.invoke(null, value);
                  } catch (Exception e) {
                      log.info("enum value of excute error : (" + castType.getName() + ") | " + value);
                      return null;
                  }
              } else if (castType == Integer.class || castType == int.class) {
                  return Integer.parseInt(value);
              } else if (castType == Long.class || castType == long.class) {
                  return Long.parseLong(value);
              } else if (castType == Double.class || castType == double.class) {
                  return Double.parseDouble(value);
              } else if (castType == Boolean.class || castType == boolean.class) {
                  return Boolean.parseBoolean(value);
              } else if (castType == Float.class || castType == float.class) {
                  return Float.parseFloat(value);
              } else if (castType == String.class) {
                  return value;
              } else if (castType == ArrayList.class || castType == List.class) {
                  ParameterizedType paramType = (ParameterizedType) m.getGenericParameterTypes()[0];
                  Class<?> paramClass = (Class<?>) paramType.getActualTypeArguments()[0];
                  List<Object> castList = new ArrayList<>();
                  String[] values = value.split(",");
                  for (String v : values) {
                      castList.add(castValue(m, paramClass, v));
                  }
  
                  return castList;
              } else {
                  log.info("invalid castType : " + castType);
                  return null;
              }
          } catch (NumberFormatException e) {
              log.info("value : " + value + " is invalid value, setter parameter type is  : " + castType);
              return null;
          }
      }
docs: Cast value object.
  
  @param m        the m
  @param castType the cast type
  @param value    the value
  @return the object