diff --git a/core/src/main/java/com/alibaba/fastjson2/util/TypeUtils.java b/core/src/main/java/com/alibaba/fastjson2/util/TypeUtils.java index 1362d53bbc..eb3fe6c8a5 100644 --- a/core/src/main/java/com/alibaba/fastjson2/util/TypeUtils.java +++ b/core/src/main/java/com/alibaba/fastjson2/util/TypeUtils.java @@ -1525,6 +1525,10 @@ public static T cast(Object obj, Class targetClass, ObjectReaderProvider return (T) JdbcSupport.createTimestamp(millis); case "java.sql.Time": return (T) JdbcSupport.createTime(millis); + case "java.time.LocalDateTime": + return (T) LocalDateTime.ofInstant( + Instant.ofEpochMilli(millis), + DateUtils.DEFAULT_ZONE_ID); default: break; } diff --git a/core/src/test/java/com/alibaba/fastjson2/issues_3000/Issue3091.java b/core/src/test/java/com/alibaba/fastjson2/issues_3000/Issue3091.java new file mode 100644 index 0000000000..93fa31e607 --- /dev/null +++ b/core/src/test/java/com/alibaba/fastjson2/issues_3000/Issue3091.java @@ -0,0 +1,26 @@ +package com.alibaba.fastjson2.issues_3000; + +import com.alibaba.fastjson2.JSONObject; +import lombok.Data; +import org.junit.jupiter.api.Test; + +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class Issue3091 { + @Test + public void test() { + String json = "{\"time\":0}"; + JSONObject jsonObject = JSONObject.parseObject(json); + Time2 bean = jsonObject.toJavaObject(Time2.class); + assertNotNull(bean.time); + assertEquals(1970, bean.time.getYear()); + } + + @Data + public static class Time2 { + private LocalDateTime time; + } +}