Skip to content

Commit 5d6c8f0

Browse files
committed
feat:优化解析类所对应json的scheme
1 parent 5e81e1d commit 5d6c8f0

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/java/org/github/azirzsk/fcp/enums/PropertyType.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.github.azirzsk.fcp.enums;
22

33
import lombok.Getter;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.github.azirzsk.fcp.annotation.Property;
46

7+
import java.lang.reflect.Field;
58
import java.util.Arrays;
69
import java.util.HashSet;
710
import java.util.Set;
@@ -10,6 +13,7 @@
1013
* @author zhangshukun
1114
* @since 2024/12/22
1215
*/
16+
@Slf4j
1317
@Getter
1418
public enum PropertyType {
1519

@@ -22,7 +26,8 @@ public enum PropertyType {
2226
FLOAT("float", "单精度浮点型", new Class<?>[]{Float.class, float.class}),
2327

2428
BOOLEAN("boolean", "布尔型", new Class<?>[]{Boolean.class, boolean.class}),
25-
;
29+
30+
OBJECT("object", "对象类型", new Class<?>[]{Object.class});;
2631

2732
private final String name;
2833

@@ -48,6 +53,13 @@ public static PropertyType parse(Class<?> type) {
4853
return value;
4954
}
5055
}
56+
// 检查类中字段是否存在@Property注解。如果有一个,则代表要使用object类型
57+
Field[] declaredFields = type.getDeclaredFields();
58+
if (Arrays.stream(declaredFields)
59+
.anyMatch(field -> field.isAnnotationPresent(Property.class))) {
60+
return OBJECT;
61+
}
62+
log.warn("暂不支持该类型:{},类中也没有标注@Property注解的字段", type);
5163
throw new IllegalArgumentException("暂不支持该类型:" + type);
5264
}
5365

0 commit comments

Comments
 (0)