[BUG] JSONB.parseObject with date relevant types throws TODO
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
一些时间相关的类使用JSONB.parseObject解析会抛出 com.alibaba.fastjson2.JSONException: TODO
使用JSON.parseObject会附带信息,建议完善报错信息:)
相关代码应该在JSONReaderJSONB.readLocalDateTime0和readLocalDate0
### 环境信息
- OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
- JDK信息: [Openjdk 17.0.6]
- 版本信息:[Fastjson2 2.0.52]
### 重现步骤
```java
import com.alibaba.fastjson2.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
public class Test_291 {
static Stream> dateTypes() {
return Stream.of(
Bean1.class,
Bean2.class,
Bean3.class,
Bean4.class
);
}
@ParameterizedTest
@MethodSource("dateTypes")
public void testJSONBParsing(Class beanClass) {
byte[] bytes = JSONB.toBytes(JSONObject.of("date", "2020-01-01 "));
System.out.println(JSONB.parseObject(bytes, beanClass));
}
@ParameterizedTest
@MethodSource("dateTypes")
public void testJSONParsing(Class beanClass) {
String json = JSON.toJSONString(JSONObject.of("date", "2020-01-01 "));
System.out.println(JSON.parseObject(json, beanClass));
}
public static class Bean1 {
public java.sql.Date date;
}
public static class Bean2 {
public java.sql.Timestamp date;
}
public static class Bean3 {
public java.time.LocalDateTime date;
}
public static class Bean4 {
public java.time.LocalDate date;
}
}
```
### 相关日志输出
com.alibaba.fastjson2.JSONException: TODO :
Contributor guide
Research direction
Run the supplied Test_291 reproduction with JSONB.parseObject and compare it with JSON.parseObject. Inspect JSONReaderJSONB.readLocalDateTime0 and readLocalDate0, then verify that the date-related types report useful parsing information instead of throwing a TODO error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100