package com.yx.face.boot.uitls;

import java.lang.reflect.Field;
import java.lang.reflect.Type;

/**
 * @ClassName BeanUtils
 * @Description TODO
 * @Author xrf
 * @Date 2021/12/3 15:15
 */
public class BeanUtils {
    /**
     * 判断对象是否为空，且对象的所有属性都为空
     * ps: boolean类型会有默认值false 判断结果不会为null 会影响判断结果
     * 序列化的默认值也会影响判断结果
     *
     * @param object
     * @return
     */
    public static boolean objCheckIsNull(Object object) {
        Class clazz = (Class) object.getClass();
        Field fields[] = clazz.getDeclaredFields();
        boolean flag = true;
        for (Field field : fields) {
            field.setAccessible(true);
            Object fieldValue = null;
            try {
                fieldValue = field.get(object);
                Type fieldType = field.getGenericType();
                String fieldName = field.getName();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            if (fieldValue != null) {
                flag = false;
                break;
            }
        }
        return flag;
    }
}
