Skip to content
New issue

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

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

Already on GitHub? # to your account

[BUG]fastjson2 将日期格式的String(yyyy-MM-dd HH:mm:ss)反序列化成Long类型出错(但是fastjson1可以) #1060

Closed
ligoudaner opened this issue Jan 9, 2023 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@ligoudaner
Copy link

ligoudaner commented Jan 9, 2023

问题描述

fastjson2 将日期格式的String(yyyy-MM-dd HH:mm:ss)反序列化成Long类型出错(但是fastjson1可以)

环境信息

请填写以下信息:

  • OS信息: macOS
  • JDK信息: jdk8
  • 版本信息:2.0.22

重现步骤

如何操作可以重现该问题:

运行下述代码即可

import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.io.Serializable;

public class DemoApplication {

    public static void main(String[] args) {
        String str = "{\"createTime\":\"2023-01-09 15:38:13\"}";
        BizDTO bizDTO = JSON.parseObject(str, BizDTO.class);
        System.err.println("createTime=" + bizDTO.getCreateTime());
    }

    @Data
    public static class BizDTO implements Serializable {
        private Long createTime;
    }
}

期待的正确结果

createTime=1673249893000

相关日志输出

Exception in thread "main" com.alibaba.fastjson.JSONException: parseLong error, value : -01-09 15:38:13
at com.alibaba.fastjson.JSON.parseObject(JSON.java:517)
at com.fintek.mx.market.user.DemoApplication.main(DemoApplication.java:12)
Caused by: com.alibaba.fastjson2.JSONException: parseLong error, value : -01-09 15:38:13
at com.alibaba.fastjson2.JSONReader.toInt64(JSONReader.java:2504)
at com.alibaba.fastjson2.JSONReader.getInt64(JSONReader.java:650)
at com.alibaba.fastjson2.JSONReaderUTF16.readInt64(JSONReaderUTF16.java:2835)
at com.alibaba.fastjson2.reader.ORG_1_1_BizDTO.readObject(Unknown Source)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:507)
... 1 more

@ligoudaner ligoudaner added the bug Something isn't working label Jan 9, 2023
@wenshao
Copy link
Member

wenshao commented Jan 9, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.23-SNAPSHOT/
问题已修复,请用2.0.23版本帮忙验证,2.0.23版本预计在1月14日前发布

@wenshao wenshao added this to the 2.0.23 milestone Jan 9, 2023
@wenshao wenshao added the fixed label Jan 9, 2023
@wenshao
Copy link
Member

wenshao commented Jan 14, 2023

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

@wenshao wenshao closed this as completed Jan 14, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants