diff --git a/src/main/java/com/alibaba/fastjson/parser/deserializer/Jdk8DateCodec.java b/src/main/java/com/alibaba/fastjson/parser/deserializer/Jdk8DateCodec.java index a65d1016ab..b76377bf4a 100644 --- a/src/main/java/com/alibaba/fastjson/parser/deserializer/Jdk8DateCodec.java +++ b/src/main/java/com/alibaba/fastjson/parser/deserializer/Jdk8DateCodec.java @@ -145,13 +145,13 @@ public T deserialze(DefaultJSONParser parser, Type type, Object fieldName, S lexer.nextToken(); if (type == LocalDateTime.class) { - return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault()); + return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), JSON.defaultTimeZone.toZoneId()); } if (type == LocalDate.class) { - return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault()).toLocalDate(); + return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), JSON.defaultTimeZone.toZoneId()).toLocalDate(); } if (type == LocalTime.class) { - return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault()).toLocalTime(); + return (T) LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), JSON.defaultTimeZone.toZoneId()).toLocalTime(); } throw new UnsupportedOperationException(); diff --git a/src/test/java/com/alibaba/json/bvt/jdk8/LocalDateTest.java b/src/test/java/com/alibaba/json/bvt/jdk8/LocalDateTest.java index ffe9bb06b8..222e5ba734 100644 --- a/src/test/java/com/alibaba/json/bvt/jdk8/LocalDateTest.java +++ b/src/test/java/com/alibaba/json/bvt/jdk8/LocalDateTest.java @@ -1,6 +1,8 @@ package com.alibaba.json.bvt.jdk8; import java.time.LocalDate; +import java.util.Locale; +import java.util.TimeZone; import junit.framework.TestCase; @@ -9,6 +11,10 @@ import com.alibaba.fastjson.JSON; public class LocalDateTest extends TestCase { + protected void setUp() throws Exception { + JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai"); + JSON.defaultLocale = Locale.CHINA; + } public void test_for_issue() throws Exception { VO vo = new VO(); diff --git a/src/test/java/com/alibaba/json/bvt/jdk8/LocalTimeTest.java b/src/test/java/com/alibaba/json/bvt/jdk8/LocalTimeTest.java index 99b3bca70d..f2fd15c608 100644 --- a/src/test/java/com/alibaba/json/bvt/jdk8/LocalTimeTest.java +++ b/src/test/java/com/alibaba/json/bvt/jdk8/LocalTimeTest.java @@ -1,6 +1,8 @@ package com.alibaba.json.bvt.jdk8; import java.time.LocalTime; +import java.util.Locale; +import java.util.TimeZone; import junit.framework.TestCase; @@ -9,7 +11,11 @@ import com.alibaba.fastjson.JSON; public class LocalTimeTest extends TestCase { - + protected void setUp() throws Exception { + JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai"); + JSON.defaultLocale = Locale.CHINA; + } + public void test_for_issue() throws Exception { VO vo = new VO(); vo.setDate(LocalTime.now());