From f1cf3179431c11a6165e1e35c1b91072899add8e Mon Sep 17 00:00:00 2001 From: yixian Date: Tue, 23 Mar 2021 17:48:48 +0800 Subject: [PATCH] compile error fix --- .../beans/DefaultClientProfile.java | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/organizations/beans/DefaultClientProfile.java b/src/main/java/au/com/royalpay/payment/manage/organizations/beans/DefaultClientProfile.java index 08a049156..e6fa261f3 100644 --- a/src/main/java/au/com/royalpay/payment/manage/organizations/beans/DefaultClientProfile.java +++ b/src/main/java/au/com/royalpay/payment/manage/organizations/beans/DefaultClientProfile.java @@ -10,13 +10,18 @@ import com.yixsoft.support.mybatis.utils.FieldDescription; import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.ObjectUtils; import org.hibernate.validator.constraints.Range; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.core.annotation.AnnotatedElementUtils; +import java.lang.reflect.InvocationTargetException; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; @JSONType(naming = PropertyNamingStrategy.SnakeCase) public class DefaultClientProfile { + private final Logger logger = LoggerFactory.getLogger(getClass()); @ProfileDesc(value = "周末延迟清算", detail = "周末交易延迟到周二清算") private boolean weekendDelay = true; @ProfileDesc("手续费包含GST") @@ -35,40 +40,46 @@ public class DefaultClientProfile { return new ClassFieldsDescription<>(getClass()).getFields().stream() .filter(field -> !"class".equalsIgnoreCase(field.getFieldName())) .map(this::convertFieldInfo) + .filter(Objects::nonNull) .collect(Collectors.toList()); } private JSONObject convertFieldInfo(FieldDescription field) { - Object value = field.readField(this); - String fieldName = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.LOWER_UNDERSCORE).convert(field.getFieldName()); - JSONObject info = new JSONObject(); - info.put("field", fieldName); - info.put("value", value); - Class fieldType = field.getMethod().getReturnType(); - if (ClassUtils.isPrimitiveOrWrapper(fieldType)) { - if (ClassUtils.isPrimitiveWrapper(fieldType)) { - fieldType = ClassUtils.wrapperToPrimitive(fieldType); - } - if (fieldType.equals(boolean.class)) { - info.put("type", "checkbox"); + try { + Object value = field.readField(this); + String fieldName = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.LOWER_UNDERSCORE).convert(field.getFieldName()); + JSONObject info = new JSONObject(); + info.put("field", fieldName); + info.put("value", value); + Class fieldType = field.getMethod().getReturnType(); + if (ClassUtils.isPrimitiveOrWrapper(fieldType)) { + if (ClassUtils.isPrimitiveWrapper(fieldType)) { + fieldType = ClassUtils.wrapperToPrimitive(fieldType); + } + if (fieldType.equals(boolean.class)) { + info.put("type", "checkbox"); + } else { + info.put("type", "number"); + } } else { - info.put("type", "number"); + info.put("type", "text"); } - } else { - info.put("type", "text"); - } - ProfileDesc getterDesc = AnnotatedElementUtils.findMergedAnnotation(field.getMethod(), ProfileDesc.class); - try { - ProfileDesc fieldDesc = AnnotatedElementUtils.findMergedAnnotation(getClass().getDeclaredField(field.getFieldName()), ProfileDesc.class); - ProfileDesc desc = ObjectUtils.defaultIfNull(getterDesc, fieldDesc); - if (desc != null) { - info.put("title", desc.value()); - info.put("detail", desc.detail()); + ProfileDesc getterDesc = AnnotatedElementUtils.findMergedAnnotation(field.getMethod(), ProfileDesc.class); + try { + ProfileDesc fieldDesc = AnnotatedElementUtils.findMergedAnnotation(getClass().getDeclaredField(field.getFieldName()), ProfileDesc.class); + ProfileDesc desc = ObjectUtils.defaultIfNull(getterDesc, fieldDesc); + if (desc != null) { + info.put("title", desc.value()); + info.put("detail", desc.detail()); + } + } catch (NoSuchFieldException e) { } - } catch (NoSuchFieldException e) { + return info; + } catch (IllegalAccessException | InvocationTargetException e) { + logger.error("failed to access getter of field {}", field.getFieldName(), e); + return null; } - return info; } public void applyToClientConfig(JSONObject client) {