فهرست منبع

bug #IBTZIX bind关键字无法反序列化LocalDate类型

everywhere.z 1 ماه پیش
والد
کامیت
5818967e66

+ 4 - 0
liteflow-core/pom.xml

@@ -31,6 +31,10 @@
 			<groupId>com.fasterxml.jackson.core</groupId>
 			<artifactId>jackson-databind</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>com.fasterxml.jackson.datatype</groupId>
+			<artifactId>jackson-datatype-jsr310</artifactId>
+		</dependency>
 		<dependency>
 			<groupId>org.yaml</groupId>
 			<artifactId>snakeyaml</artifactId>

+ 4 - 4
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) {

+ 12 - 0
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());
+	}
+
 }

+ 28 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/FCmp.java

@@ -0,0 +1,28 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @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);
+		}
+
+	}
+
+}

+ 54 - 0
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;
+    }
+}

+ 5 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow1.xml

@@ -20,4 +20,9 @@
     <chain id="chain4">
         THEN(d, sub.bind("k1", "test2"))
     </chain>
+
+    <chain id="chain5">
+        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));
+    </chain>
 </flow>

+ 6 - 1
pom.xml

@@ -39,7 +39,7 @@
 	</scm>
 
 	<properties>
-		<revision>2.13.0</revision>
+		<revision>2.13.1</revision>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 		<maven.compiler.source>8</maven.compiler.source>
@@ -136,6 +136,11 @@
 				<artifactId>jackson-databind</artifactId>
 				<version>${jackson.version}</version>
 			</dependency>
+			<dependency>
+				<groupId>com.fasterxml.jackson.datatype</groupId>
+				<artifactId>jackson-datatype-jsr310</artifactId>
+				<version>${jackson.version}</version>
+			</dependency>
 			<dependency>
 				<groupId>org.yaml</groupId>
 				<artifactId>snakeyaml</artifactId>