public static void checkObject(Object data, Class<?> outType, Checkable checkable)
     throws CheckableDataException {
   checkIsNull(data, checkable);
   if (outType.isArray()) {
     checkArray((Object[]) data, outType, checkable);
   } else if (outType == Date.class || StringUtils.isNotEmpty(checkable.dateFormat())) {
     checkDate(ConvertUtil.toString(data), checkable);
   } else if (outType == String.class) {
     checkString(ConvertUtil.toString(data), checkable);
   } else if (outType == Double.class || outType == double.class) {
     checkDouble(ConvertUtil.toString(data), checkable);
   } else if (outType == Float.class || outType == float.class) {
     checkFloat(ConvertUtil.toString(data), checkable);
   } else if (outType == Integer.class || outType == int.class) {
     checkInteger(ConvertUtil.toString(data), checkable);
   } else if (!ClassUtil.isJavaType(outType)) {
     Field[] fields = outType.getDeclaredFields();
     for (int i = 0; i < fields.length; i++) {
       if (fields[i].isAnnotationPresent(Checkable.class)) {
         Checkable tmpCheckable = fields[i].getAnnotation(Checkable.class);
         try {
           fields[i].setAccessible(true);
           Object fieldValue = fields[i].get(data);
           fields[i].setAccessible(false);
           checkObject(fieldValue, fields[i].getType(), tmpCheckable);
         } catch (Exception e) {
           throw new CheckableDataException(e.getMessage(), e);
         }
       }
     }
   }
 }
示例#2
0
 public static Map<String, Field> getClassAllFields(Class<?> classInfo) {
   Class<?> tmpClass = classInfo;
   if (!tmpClass.isInterface() && !ClassUtil.isJavaType(tmpClass)) {
     Map<String, Field> fieldMap = new HashMap<>();
     do {
       Field[] fields = tmpClass.getDeclaredFields();
       for (int f = 0; f < fields.length; f++) {
         fieldMap.put(fields[f].getName(), fields[f]);
       }
     } while ((tmpClass = tmpClass.getSuperclass()) != Object.class);
     return fieldMap;
   }
   return null;
 }