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] Date 类型处理异常 #467

Closed
JiakunXu opened this issue Jun 14, 2022 · 2 comments
Closed

[BUG] Date 类型处理异常 #467

JiakunXu opened this issue Jun 14, 2022 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@JiakunXu
Copy link

JiakunXu commented Jun 14, 2022

问题描述

对象中包含 Date 类型的属性,通过 @JSONField 指定格式化,当 Date 类型的属性值为 "",parseObject 会报错;当 Date 类型的属性为 null,parseObject 正常

Fastjson 1.2.83 没有这个问题

环境信息

  • 版本信息:[Fastjson2 2.0.7]

重现步骤

  1. 使用 JSON.parseObject 方法
  2. 输入 {"date":""} 数据
  3. 出现 Text '' could not be parsed at index 0 错误
    @JSONField(format = "yyyy-MM-dd")
    private Date              date;

相关日志输出

Exception in thread "main" java.time.format.DateTimeParseException: Text '' could not be parsed at index 0
	at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
	at java.time.LocalDate.parse(LocalDate.java:400)
	at com.alibaba.fastjson2.reader.ObjectReaderImplDate.readDate(ObjectReaderImplDate.java:105)
	at com.alibaba.fastjson2.reader.ObjectReaderImplDate.readObject(ObjectReaderImplDate.java:71)
	at com.alibaba.fastjson2.reader.ObjectReader_1.readObject(Unknown Source)
	at com.alibaba.fastjson2.JSON.parseObject(JSON.java:421)
@JiakunXu JiakunXu added the bug Something isn't working label Jun 14, 2022
@wenshao wenshao added this to the 2.0.8 milestone Jun 14, 2022
@wenshao
Copy link
Member

wenshao commented Jun 14, 2022

@wenshao
Copy link
Member

wenshao commented Jun 25, 2022

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

@wenshao wenshao closed this as completed Jun 25, 2022
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

2 participants