Browse Source

[Fix-16279] Support Java 8 date/time type `java.time.OffsetDateTime` (#16304)

* [Fix-16279] Support Java 8 date/time type `java.time.OffsetDateTime`
dev
zuo 4 months ago committed by GitHub
parent
commit
8d1680d2f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      dolphinscheduler-bom/pom.xml
  2. 2
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
  3. 2
      dolphinscheduler-dist/release-docs/LICENSE
  4. 18
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/model/JSONUtilsTest.java
  5. 2
      tools/dependencies/known-dependencies.txt

6
dolphinscheduler-bom/pom.xml

@ -360,7 +360,11 @@
<artifactId>jackson-core</artifactId> <artifactId>jackson-core</artifactId>
<version>${jackson.version}</version> <version>${jackson.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<!--protostuff--> <!--protostuff-->
<dependency> <dependency>
<groupId>io.protostuff</groupId> <groupId>io.protostuff</groupId>

2
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java

@ -60,6 +60,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode; import com.fasterxml.jackson.databind.node.TextNode;
import com.fasterxml.jackson.databind.type.CollectionType; import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.common.base.Strings; import com.google.common.base.Strings;
/** /**
@ -78,6 +79,7 @@ public final class JSONUtils {
.configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true) .configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
.configure(REQUIRE_SETTERS_FOR_GETTERS, true) .configure(REQUIRE_SETTERS_FOR_GETTERS, true)
.configure(FAIL_ON_EMPTY_BEANS, false) .configure(FAIL_ON_EMPTY_BEANS, false)
.addModule(new JavaTimeModule())
.addModule(new SimpleModule() .addModule(new SimpleModule()
.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer()) .addSerializer(LocalDateTime.class, new LocalDateTimeSerializer())
.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer())) .addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer()))

2
dolphinscheduler-dist/release-docs/LICENSE vendored

@ -294,7 +294,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
jackson-core-asl 1.9.13: https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-core-asl/1.9.13, Apache 2.0 jackson-core-asl 1.9.13: https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-core-asl/1.9.13, Apache 2.0
jackson-databind 2.13.4: https://github.com/FasterXML/jackson-databind, Apache 2.0 jackson-databind 2.13.4: https://github.com/FasterXML/jackson-databind, Apache 2.0
jackson-datatype-jdk8 2.13.0: https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/2.13.0, Apache 2.0 jackson-datatype-jdk8 2.13.0: https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/2.13.0, Apache 2.0
jackson-datatype-jsr310 2.13.0: https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.13.0, Apache 2.0 jackson-datatype-jsr310 2.13.4: https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.13.4, Apache 2.0
jackson-mapper-asl 1.9.13: https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl/1.9.13, Apache 2.0 jackson-mapper-asl 1.9.13: https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl/1.9.13, Apache 2.0
jackson-module-parameter-names 2.13.0: https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-parameter-names/2.13.0, Apache 2.0 jackson-module-parameter-names 2.13.0: https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-parameter-names/2.13.0, Apache 2.0
javax.jdo-3.2.0-m3: https://mvnrepository.com/artifact/org.datanucleus/javax.jdo/3.2.0-m3, Apache 2.0 javax.jdo-3.2.0-m3: https://mvnrepository.com/artifact/org.datanucleus/javax.jdo/3.2.0-m3, Apache 2.0

18
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/model/JSONUtilsTest.java

@ -22,6 +22,9 @@ import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.plugin.task.api.enums.DataType; import org.apache.dolphinscheduler.plugin.task.api.enums.DataType;
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct; import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -270,4 +273,19 @@ public class JSONUtilsTest {
} }
@Test
public void toOffsetDateTimeNodeTest() {
TimeZone timeZone = TimeZone.getTimeZone("UTC");
JSONUtils.setTimeZone(timeZone);
LocalDateTime localDateTime = LocalDateTime.of(2024, 7, 10, 15, 0, 0);
OffsetDateTime offsetDateTime = OffsetDateTime.of(localDateTime, ZoneOffset.ofHours(0));
Map<String, OffsetDateTime> map = new HashMap<>();
map.put("time", offsetDateTime);
JsonNode jsonNodes = JSONUtils.toJsonNode(map);
String s = JSONUtils.toJsonString(jsonNodes);
String json = "{\"time\":\"2024-07-10T15:00:00Z\"}";
Assertions.assertEquals(json, s);
}
} }

2
tools/dependencies/known-dependencies.txt

@ -115,7 +115,7 @@ jackson-databind-2.13.4.jar
jackson-dataformat-cbor-2.13.3.jar jackson-dataformat-cbor-2.13.3.jar
jackson-dataformat-yaml-2.13.3.jar jackson-dataformat-yaml-2.13.3.jar
jackson-datatype-jdk8-2.13.3.jar jackson-datatype-jdk8-2.13.3.jar
jackson-datatype-jsr310-2.13.3.jar jackson-datatype-jsr310-2.13.4.jar
jackson-jaxrs-base-2.13.3.jar jackson-jaxrs-base-2.13.3.jar
jackson-jaxrs-json-provider-2.13.3.jar jackson-jaxrs-json-provider-2.13.3.jar
jackson-mapper-asl-1.9.13.jar jackson-mapper-asl-1.9.13.jar

Loading…
Cancel
Save