fix 修复@EnumValue应用在接口方法且返回类型为泛型时失效的问题

This commit is contained in:
CShisan 2025-11-07 18:00:49 +08:00
parent 70a97bb0eb
commit c1cd6dcecd

View File

@ -77,13 +77,22 @@ public class EnumWrapper<E extends Enum<E>> {
if (!(methodName.startsWith("get") && methodName.length() > 3)) { if (!(methodName.startsWith("get") && methodName.length() > 3)) {
throw new IllegalStateException("Can not find get method \"" + methodName + "()\" in enum: " + enumClass.getName()); throw new IllegalStateException("Can not find get method \"" + methodName + "()\" in enum: " + enumClass.getName());
} }
String enumValueFieldName;
if (methodName.startsWith("get")) {
enumValueFieldName = StringUtil.firstCharToLowerCase(enumValueMethod.getName().substring(3));
} else {
enumValueFieldName = enumValueMethod.getName().toLowerCase();
}
enumValueField = ClassUtil.getFirstField(enumClass, field -> enumValueFieldName.equals(field.getName()));
if (enumValueField != null) {
propertyType = ClassUtil.getWrapType(enumValueField.getType());
} else {
throw new IllegalStateException("Can not find field \"" + enumValueFieldName + "()\" in enum: " + enumClass.getName());
}
this.getterMethod = enumValueMethod; this.getterMethod = enumValueMethod;
this.hasEnumValueAnnotation = true; this.hasEnumValueAnnotation = true;
Class<?> returnType = enumValueMethod.getReturnType();
if (returnType.isPrimitive()) {
returnType = ConvertUtil.primitiveToBoxed(returnType);
}
this.propertyType = returnType;
} }
} }
} }