diff --git a/io.sc.engine.rule.core/src/main/resources/io/sc/engine/rule/core/code/java/template/impl/lib.tpl b/io.sc.engine.rule.core/src/main/resources/io/sc/engine/rule/core/code/java/template/impl/lib.tpl index 91319892..f9e13db4 100644 --- a/io.sc.engine.rule.core/src/main/resources/io/sc/engine/rule/core/code/java/template/impl/lib.tpl +++ b/io.sc.engine.rule.core/src/main/resources/io/sc/engine/rule/core/code/java/template/impl/lib.tpl @@ -129,6 +129,9 @@ public class #(className(lib.code,lib.version)) { @JsonIgnoreProperties(ignoreUnknown=true) static class Argument { #(tabs(IndicatorGenerator.generateFields(lib.indicators),2)) + + Argument() throws Exception {} + public static Argument convertArgument(Map map) throws Exception { if(map!=null){ Argument arg =new Argument(); diff --git a/io.sc.platform.util/src/main/java/io/sc/platform/util/ReflectUtil.java b/io.sc.platform.util/src/main/java/io/sc/platform/util/ReflectUtil.java index 199fb12f..740c9876 100644 --- a/io.sc.platform.util/src/main/java/io/sc/platform/util/ReflectUtil.java +++ b/io.sc.platform.util/src/main/java/io/sc/platform/util/ReflectUtil.java @@ -2,6 +2,7 @@ package io.sc.platform.util; import org.springframework.util.StringUtils; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -134,4 +135,32 @@ public class ReflectUtil { Method method =clazz.getDeclaredMethod(methodName, innerParameterTypes); return (T)method.invoke(clazz, parameters); } + + public static Object getFieldValue(Object target, String fieldName) throws IllegalAccessException { + if(target==null) { return null; } + if(!StringUtils.hasText(fieldName)) { return null; } + Field field =null; + try{ + field =target.getClass().getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + return null; + } + if(field==null) { return null; } + field.setAccessible(true); + return field.get(target); + } + + public static void setFieldValue(Object target, String fieldName,Object value) throws IllegalAccessException { + if(target==null) { return; } + if(!StringUtils.hasText(fieldName)) { return; } + Field field =null; + try{ + field =target.getClass().getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + return; + } + if(field==null) { return; } + field.setAccessible(true); + field.set(target,value); + } }