fastjson2
fastjson2 copied to clipboard
[BUG] JSON.parseObject with unquote date
问题描述
解析没有”“的date时,fastjson-2.0.50返回一个错误的时间,fastjson2-2.0.50和fastjson-1.2.83抛出异常。建议兼容包抛出适当异常,避免返回错误的值。
环境信息
- OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
- JDK信息: [Openjdk 17.0.6]
- 版本信息:[Fastjson2 2.0.50]
重现步骤
import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue1276_10 {
@Test
public void test() {
Date sendTime = JSON.parseObject("2023-03-24 11:10:00", Date.class);
System.out.println(sendTime);
}
@Test
public void test2_fj() {
Date sendTime2 = com.alibaba.fastjson.JSON.parseObject("2023-03-24 11:10:00", Date.class);
System.out.println(sendTime2);
}
@Test
public void test3() {
Date sendTime1 = JSON.parseObject("\"2023-03-24 11:10:00\"", Date.class);
Date sendTime2 = com.alibaba.fastjson.JSON.parseObject("\"2023-03-24 11:10:00\"", Date.class);
assertEquals(sendTime1, sendTime2);
}
}
相关日志输出
// fastjson 2.0.50 Thu Jan 01 08:00:02 CST 1970