package com.bonus.canteen.core.common.utils;

import com.bonus.canteen.core.order.business.OrderBusiness;
import com.bonus.common.core.exception.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;

public class ObjectUtils {
    private static final Logger log = LoggerFactory.getLogger(ObjectUtils.class);
    public static void setAllFieldsToNull(Object obj) {
        for (Field field : obj.getClass().getDeclaredFields()) {
            if("serialVersionUID".equals(field.getName())) {
                continue;
            }
            field.setAccessible(true);
            try {
                field.set(obj, null);
            } catch (IllegalAccessException e) {
                log.error("setAllFieldsToNull error", e);
                throw new ServiceException("系统异常");
            }
        }
    }
}
