diff --git a/liteflow-core/pom.xml b/liteflow-core/pom.xml index b6da77fe2..3eebab572 100644 --- a/liteflow-core/pom.xml +++ b/liteflow-core/pom.xml @@ -31,6 +31,10 @@ com.fasterxml.jackson.core jackson-databind + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + org.yaml snakeyaml diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java index 6d8815938..9183ac973 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java @@ -7,14 +7,12 @@ 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.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 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.Collections; -import java.util.List; -import java.util.TimeZone; +import java.util.*; /** * JSON 工具类 @@ -33,6 +31,8 @@ public class JsonUtil { static { objectMapper.setTimeZone(TimeZone.getDefault()); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + JavaTimeModule javaTimeModule = new JavaTimeModule(); + objectMapper.registerModule(javaTimeModule); } public static String toJsonString(Object object) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest1.java index 106da8382..db89bd946 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest1.java @@ -4,6 +4,7 @@ import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.util.JsonUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -12,6 +13,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import javax.annotation.Resource; +import java.util.Optional; /** * springboot环境EL常规的例子测试 @@ -71,4 +73,14 @@ public class BindDataSpringbootTest1 extends BaseTest { Assertions.assertEquals("test2", context.getData("c")); Assertions.assertTrue(response.isSuccess()); } + + // 测试bind一个对象,并且对象中的birth类型为LocalDate + @Test + public void testBind5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + DefaultContext context = response.getFirstContextBean(); + System.out.println(JsonUtil.toJsonString(context.getData("f"))); + Assertions.assertTrue(response.isSuccess()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/FCmp.java new file mode 100644 index 000000000..235de56fe --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/FCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.bindData.cmp1; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + Person bindValue = this.getBindData("key", Person.class); + if (bindValue != null) { + context.setData(this.getNodeId(), bindValue); + } + + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/Person.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/Person.java new file mode 100644 index 000000000..a3ea99c44 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/Person.java @@ -0,0 +1,54 @@ +package com.yomahub.liteflow.test.bindData.cmp1; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Date; + +public class Person { + + private String name; + private int age; + private Date birth1; + private LocalDate birth2; + private LocalDateTime birth3; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Date getBirth1() { + return birth1; + } + + public void setBirth1(Date birth1) { + this.birth1 = birth1; + } + + public LocalDate getBirth2() { + return birth2; + } + + public void setBirth2(LocalDate birth2) { + this.birth2 = birth2; + } + + public LocalDateTime getBirth3() { + return birth3; + } + + public void setBirth3(LocalDateTime birth3) { + this.birth3 = birth3; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow1.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow1.xml index 0aeacf067..3874e191b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow1.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow1.xml @@ -20,4 +20,9 @@ THEN(d, sub.bind("k1", "test2")) + + + v = "{\"name\":\"jack\", \"age\":19, \"birth1\":\"1990-06-01T12:00:00\", \"birth2\":\"1990-06-01\", \"birth3\":\"1990-06-01T12:00:00\"}"; + THEN(f.bind("key",v)); + \ No newline at end of file diff --git a/pom.xml b/pom.xml index e7ea2759c..e1df3662a 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ - 2.13.0 + 2.13.1 UTF-8 UTF-8 8 @@ -136,6 +136,11 @@ jackson-databind ${jackson.version}
+ + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + org.yaml snakeyaml