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] Parse day-month-year format json string #2757

Closed
Cooper-Zhong opened this issue Jun 30, 2024 · 3 comments
Closed

[BUG] Parse day-month-year format json string #2757

Cooper-Zhong opened this issue Jun 30, 2024 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@Cooper-Zhong
Copy link
Contributor

问题描述

对于 日-月-年 格式的字符串,fastjson 1.x 可以解析,fastjson兼容无法解析。请问是否考虑支持呢

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson 2.0.51]

重现步骤

import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.Test;

import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Test_112 {
    @Test
    public void test() throws Exception {
        Model model = JSON.parseObject("{\"date\":\"01-03-2022 12:00:00\"}", Model.class);
        assertEquals(new Date(122, 2, 1, 12, 0, 0), model.date);
    }

    public static class Model {
        public Date date;
    }
}

相关日志输出

java.time.format.DateTimeParseException: illegal input 01-01-2022 12:00:00
at com.alibaba.fastjson2.util.DateUtils.parseMillis19(DateUtils.java:9763)
at com.alibaba.fastjson2.JSONReaderUTF8.readMillis19(JSONReaderUTF8.java:6713)
at com.alibaba.fastjson2.JSONReader.readMillisFromString(JSONReader.java:1557)
at com.alibaba.fastjson2.JSONReader.readDate(JSONReader.java:1381)
at com.alibaba.fastjson2.reader.ORG_1_1_Model.readObject(Unknown Source)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:542)

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label Jun 30, 2024
@wenshao
Copy link
Member

wenshao commented Jun 30, 2024

这个格式怎么来的?

@Cooper-Zhong
Copy link
Contributor Author

自动化测试构建得到的,日-月-年主要是国外的使用方式,然后发现在1.2.83上居然也能够正常解析。

@wenshao wenshao added this to the 2.0.52 milestone Jul 7, 2024
@wenshao wenshao added the fixed label Jul 7, 2024
@wenshao
Copy link
Member

wenshao commented Jul 14, 2024

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

@wenshao wenshao closed this as completed Jul 14, 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