alibaba / fastjson2

🚄 FASTJSON2 is a Java JSON library with excellent performance.
Apache License 2.0
3.59k stars 471 forks source link

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

Open Cooper-Zhong opened 1 week ago

Cooper-Zhong commented 1 week ago

问题描述

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

环境信息

重现步骤


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)

wenshao commented 1 week ago

这个格式怎么来的?

Cooper-Zhong commented 1 week ago

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