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

Date格式反序列化异常 #2199

Closed
zzqw opened this issue Jan 18, 2024 · 3 comments
Closed

Date格式反序列化异常 #2199

zzqw opened this issue Jan 18, 2024 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@zzqw
Copy link

zzqw commented Jan 18, 2024

问题描述

简要描述您碰到的问题。
实体类使用@JSONField(format = "yyyy-MM-dd hh:mm:ss")定义日期格式字段,在反序列化的时候抛出异常,使用1.X是可以正常反序列化的

环境信息

请填写以下信息:

  • OS信息: [e.g.:Windows11]
  • JDK信息: [e.g.:Openjdk 1.8.0_381]
  • 版本信息:[e.g.:Fastjson2 2.0.45]

重现步骤

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

  1. 使用 xxx.xxx 方法
  2. 输入 ... 数据
  3. 出现 ... 错误
//可在此输入示例代码

public class Test {

@Data
public static class Obj1 {
    @JSONField(format = "yyyy-MM-dd hh:mm:ss")
    private Date startTime;
}

public static void main(String[] args) throws IOException {
    Obj1 orderBO = new Obj1();
    orderBO.setStartTime(new Date());
    String s  = JSONObject.toJSONString(orderBO);
    System.out.println(s);
    System.out.println(JSONObject.parseObject(s, Obj1.class));
}

}

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

相关日志输出

请复制并粘贴任何相关的日志输出。
image

这是使用1.X的反序列化结果
image

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@zzqw zzqw added the bug Something isn't working label Jan 18, 2024
@wenshao
Copy link
Member

wenshao commented Jan 18, 2024

你要的是:

"yyyy-MM-dd HH:mm:ss"

HH应该是大写

@wenshao
Copy link
Member

wenshao commented Jan 18, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.46-SNAPSHOT/
兼容问题已修复,请帮忙用2.0.46-SNAPSHOT版本验证,正式版本预计在3月初发布。

@wenshao wenshao added the fixed label Jan 18, 2024
@wenshao wenshao added this to the 2.0.46 milestone Jan 18, 2024
@wenshao
Copy link
Member

wenshao commented Jan 29, 2024

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

@wenshao wenshao closed this as completed Jan 29, 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