alibaba / alibaba/fastjson2

[BUG]LocalDateTime转换的时候会有个yyyy-MM-ddTHH:mm:ss?

Open
#1,600 11 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
*LocalDateTime转换的时候会有个yyyy-MM-ddTHH:mm:ss*

### 环境信息
*请填写以下信息:*

- OS信息: [全平台]
- JDK信息: [Openjdk 1.8.0_312]
- 版本信息:[
com.alibaba.fastjson2
fastjson2-extension-spring5
2.0.32
]

### 重现步骤

1. 使用 `SON.parseObject()` 方法
2. 输入 `{
"id": "5C9D8F9E-20A9-46C7-9AD2-51E4DF518229",
"sign": "0406246538b1507126e877db5d07b647",
"data": {
"activeTime": "2023-06-26 09:45:23",
"softVersion": "1.0.0",
},
"time": "2023-06-26 09:45:23"
}` 数据
3. 出现 `activeTime2023-06-26T09:45:23 birth2023-06-26T09:45:23` 错误
```java
WdDataParams registerReply = JSON.parseObject(json, new TypeReference>() {
});
```
```java
public class WdMqttBean {
/**
* 消息id
*/
private String id;

/**
* 消息内容
*/
private T data;

/**
* 发送时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime time;

/**
* sign签名
*/
private String sign;
}
```
```java
public class WdRegisterReply {

/**
* 出厂时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime birth;

/**
* 激活时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime activeTime;

}
```

### 期待的正确结果
*应该是转换成activeTime2023-06-26 09:45:23birth2023-06-26 09:45:23这个样子才对*

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

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

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue through JSON.parseObject with the supplied WdMqttBean and WdRegisterReply classes, LocalDateTime fields, annotations, and sample input. Trace how the format annotations are handled during deserialization and verify that the resulting time values preserve the expected yyyy-MM-dd HH:mm:ss representation.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.