Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] JSON.parseObject with unquote date #2598

Closed
Cooper-Zhong opened this issue May 18, 2024 · 2 comments
Closed

[BUG] JSON.parseObject with unquote date #2598

Cooper-Zhong opened this issue May 18, 2024 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@Cooper-Zhong
Copy link

问题描述

解析没有”“的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

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label May 18, 2024
hnyyghk added a commit to hnyyghk/fastjson2 that referenced this issue May 21, 2024
hnyyghk added a commit to hnyyghk/fastjson2 that referenced this issue May 21, 2024
hnyyghk added a commit to hnyyghk/fastjson2 that referenced this issue May 21, 2024
@wenshao wenshao added this to the 2.0.51 milestone May 21, 2024
@wenshao wenshao added the fixed label May 21, 2024
@wenshao
Copy link
Member

wenshao commented May 21, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.51-SNAPSHOT/
问题已修复,请帮忙用2.0.51-SNAPSHOT版本验证

@wenshao
Copy link
Member

wenshao commented Jun 1, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.51
问题已修复,请用新版本

@wenshao wenshao closed this as completed Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants