mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
enhancemnet #IANY4U 在NodeComponent中添加getCmpList方法
This commit is contained in:
@@ -29,6 +29,7 @@ import com.yomahub.liteflow.util.JsonUtil;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
@@ -414,6 +415,14 @@ public abstract class NodeComponent{
|
||||
return JsonUtil.parseObject(cmpData, clazz);
|
||||
}
|
||||
|
||||
public <T> List<T> getCmpList(Class<T> clazz) {
|
||||
String cmpData = getRefNode().getCmpData();
|
||||
if (StrUtil.isBlank(cmpData)) {
|
||||
return null;
|
||||
}
|
||||
return JsonUtil.parseList(cmpData, clazz);
|
||||
}
|
||||
|
||||
public Integer getLoopIndex() {
|
||||
return this.getRefNode().getLoopIndex();
|
||||
}
|
||||
|
||||
@@ -3,13 +3,17 @@ package com.yomahub.liteflow.util;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import com.yomahub.liteflow.exception.JsonProcessException;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
@@ -73,4 +77,18 @@ public class JsonUtil {
|
||||
throw new JsonProcessException(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<T> parseList(String json, Class<T> clazz) {
|
||||
if (StrUtil.isEmpty(json)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
CollectionType listType = objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, clazz);
|
||||
return objectMapper.readValue(json, listType);
|
||||
} catch (IOException e) {
|
||||
String errMsg = StrUtil.format("Error while parsing text [{}],reason: {}", json, e.getMessage());
|
||||
LOG.error(e.getMessage(), e);
|
||||
throw new JsonProcessException(errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user