You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importjava.util.Date;
importjava.util.TimeZone;
importcom.alibaba.fastjson.JSON;
importcom.alibaba.fastjson.serializer.SerializeConfig;
importcom.alibaba.fastjson.serializer.SerializerFeature;
importorg.junit.Test;
importstaticorg.junit.Assert.assertEquals;
publicclassTest961 {
@TestpublicvoidtestTimezoneConversionDuringDaylightSavingTime() {
// Set the system time zone to Los Angeles (PST/PDT)TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
// Create a Date object within the daylight saving time period in Los AngelesDatedateWithinDST = newDate(1597848000000L); // Aug 19, 2020 12:00:00 AM PDT// Create a SerializeConfig instanceSerializeConfigconfig = newSerializeConfig();
// Serialize the Date object using the toJSONString method with UseISO8601DateFormat feature and configStringjsonString = JSON.toJSONString(dateWithinDST, config, null, null, 0, SerializerFeature.UseISO8601DateFormat);
// Expected outcome: The serialized output should reflect the correct timezone offset including daylight saving time (PDT)assertEquals("2020-08-19T07:40:00-07:00", jsonString); // PDT offset: -07:00
}
}
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:1269)
at Test961.testTimezoneConversionDuringDaylightSavingTime(Test961.java:25)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.NullPointerException: Cannot read the array length because "" is null
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:1251)
... 26 more*
附加信息
在fastjson 1.2.83版本可以正常序列化但是输出貌似有点奇怪:org.junit.ComparisonFailure:
Expected :2020-08-19T07:40:00-07:00
Actual :"2020-08-19T07:40:00-07:00"
The text was updated successfully, but these errors were encountered:
问题描述
简要描述您碰到的问题。
在使用fastjson 1.2.83可以正常序列化,用2.0.49则抛出空指针异常
环境信息
请填写以下信息:
重现步骤
如何操作可以重现该问题:
Test case
期待的正确结果
能够正确序列化
相关日志输出
*com.alibaba.fastjson.JSONException: toJSONString error
Caused by: java.lang.NullPointerException: Cannot read the array length because "" is null
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:1251)
... 26 more*
附加信息
在fastjson 1.2.83版本可以正常序列化但是输出貌似有点奇怪:org.junit.ComparisonFailure:
Expected :2020-08-19T07:40:00-07:00
Actual :"2020-08-19T07:40:00-07:00"
The text was updated successfully, but these errors were encountered: