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

针对 cn.hutool.core.date.DateTime 类型的属性反序列化时报错 #3297

Open
Taogang00 opened this issue Jan 20, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@Taogang00
Copy link

问题描述

针对 cn.hutool.core.date.DateTime 类型的属性反序列化时报错

环境信息

请填写以下信息:

  • OS信息: win10
  • JDK信息: jdk17
  • 版本信息:fastsjon2 目前最新

重现步骤

运行main

public class DateTimeTest {

    public static void main(String[] args) {
        JSON.configReaderDateFormat("yyyy-MM-dd HH:mm:ss");
        JSON.configWriterDateFormat("yyyy-MM-dd HH:mm:ss");

        Bean bean1 = new Bean();
        bean1.setDate3(new DateTime());

        String jsonString = JSON.toJSONString(bean1);
        System.out.println(jsonString);

        Bean bean2 = JSON.parseObject(jsonString, Bean.class);
        System.out.println(bean2);
    }


    @Data
    static class Bean {
        public DateTime date3;
    }
}

期待的正确结果

反序列化对象正常

相关日志输出

{"date3":"2025-01-20 13:00:09"}
Exception in thread "main" com.alibaba.fastjson2.JSONException: expect ':', but 125, offset 10, character ", line 1, column 10, fastjson-version 2.0.54 {"date3":"2025-01-20 13:00:09"}
at com.alibaba.fastjson2.JSONReaderASCII.readFieldNameHashCode(JSONReaderASCII.java:390)
at com.alibaba.fastjson2.reader.ORG_2_11_DateTime.readObject(Unknown Source)
at com.alibaba.fastjson2.reader.ORG_1_1_Bean.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:864)
at com.guanwei.fastjson2.DateTimeTest.main(DateTimeTest.java:21)

Process finished with exit code 1

附加信息

Image

@Taogang00 Taogang00 added the bug Something isn't working label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant