Skill/spring

출력 변수 처리

진열사랑 2024. 5. 22. 15:17

public static void setCIMaskedValue(Object parameter) {
        try {
        String maskedValue = null;
        Class<?> orgin = parameter.getClass();
        Field[] fieldsArr = orgin.getDeclaredFields();
        List<Field> allFields = new ArrayList<>(Arrays.asList(fieldsArr));

        for (Field field : allFields) {
                if (CommonUtil.isCIField(field)) {
                        CIFieldType enumCIFiledType = field.getAnnotation(CIField.class).type();

                        field.setAccessible(true);

                        if (field.get(parameter) != null) {
                                String parameterValue = field.get(parameter).toString();

                                switch (enumCIFiledType) {
                                        case Name:
                                        case Account:
                                        case CouponNo:
                                                maskedValue = getMaskedName(parameterValue);
                                                break;
                                        case Email:
                                                maskedValue =                                                                 getMaskedEmail(parameterValue);
                                                break;
                                        case PhoneNo:
                                                maskedValue =                                 getMaskedPhoneNumber(parameterValue);
                                                break;

                                }
                         }

                        field.set(parameter, maskedValue);
                }
        }
}
catch (Exception ex) { }
}