env 注入的 list 和 使用 字符串定义的 list 类型不一致
Closed this issue · 3 comments
StringKe commented
使用 env 注入来自 java 里的 List<Map<Object,Object>> 在自定义函数里获取到的类型是 java.util.ImmutableCollections
使用字符串拼接 seq.list 拼接的在自定义函数中获取到的类型是 java.util.ArrayList
killme2008 commented
这不是很正常吗? 有什么问题呢?
StringKe commented
我尝试过几次,有时候两个都会取到 ArrayList 取到 ImmutableCollections ,排序的 sort 方法就不存在了。
目前测试是正常的,但没找到复现的方式。
StringKe commented
调度代码
@Test
void call() {
List<Map<String, Object>> list = List.of(
Map.of("min", 0, "max", 100, "value", Map.of("a", 1)),
Map.of("min", 100, "max", 200, "value", Map.of("a", 2)),
Map.of("min", 200, "max", 300, "value", Map.of("a", 3)));
Expression exp1 = engine.compile("RangeFindMin(decimal(100), list)");
Object result1 = exp1.execute(exp1.newEnv("list", list));
System.out.println("result1 = " + result1);
}
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
this.validate(env, List.of(arg1, arg2));
BigDecimal target = ExpUtils.getDecimal(env, arg1);
Object arg2Value = arg2.getValue(env);
System.out.println("arg2Value = " + arg2Value);
System.out.println("arg2Value type = " + arg2Value.getClass().getName());
List<Map<String, Object>> fan_wei = (List<Map<String, Object>>) arg2Value;;
System.out.println("arg2 value = " + fan_wei);
System.out.println("arg2 type = " + fan_wei.getClass().getName());
}
输出
arg2Value = [{value={a=1}, max=100, min=0}, {value={a=2}, max=200, min=100}, {value={a=3}, max=300, min=200}]
arg2Value type = java.util.ImmutableCollections$ListN
arg2 value = [{value={a=1}, max=100, min=0}, {value={a=2}, max=200, min=100}, {value={a=3}, max=300, min=200}]
arg2 type = java.util.ImmutableCollections$ListN