Skip to content

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

@JiakunXu

Description

@JiakunXu

问题描述

对象中包含 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions