[BUG]@JSONField(format="xxxxx") 对http请求对象的LocalDateTime字段不生效!!!
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
@JSONField(format="xxxxx") 对http请求对象的LocalDateTime字段不生效!!!
我感觉是:下图中,第40行和第63行代码对 `yyyyMMddhhmmss19` 属性进行判断是多余的,删除掉应该就好了。理论上代码应该执行**第41行**才对。
### 环境信息
- OS信息: [e.g.:Windows]
- JDK信息: [e.g.:Openjdk 1.17.0_13]
- 版本信息:[e.g.:Fastjson2 2.0.54]
### 重现步骤
1. 基于应用程序其他部分需要,`FastJsonHttpMessageConverter`的默认格式设置为 "yyyy-MM-dd HH:mm:ss.SSS"
`config.setDateFormat("yyyy-MM-dd HH:mm:ss.SSS");`
2. 某个 HTTP Request 对象的输入格式设置为 "yyyy-MM-dd HH:mm:ss"
```
class XxxRequest {
/**
* 计划开始时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime planStartTime;
}
```
3. 实际使用过程中,@JSONField(format="xxxxx") 对http请求对象的LocalDateTime字段不生效!!!

4. 异常堆栈
```
Caused by: java.time.format.DateTimeParseException: Text '2025-01-25 01:29:30' could not be parsed at index 19
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2052) ~[?:?]
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1954) ~[?:?]
at java.base/java.time.LocalDateTime.parse(LocalDateTime.java:494) ~[?:?]
at com.alibaba.fastjson2.JSONReader.readLocalDateTime(JSONReader.java:1320) ~[fastjson2-2.0.54.jar:?]
at com.alibaba.fastjson2.reader.ObjectReaderImplLocalDateTime.readObject(ObjectReaderImplLocalDateTime.java:64) ~[fastjson2-2.0.54.jar:?]
at com.alibaba.fastjson2.reader.ORG_3_14_CreateSendMailTaskRequest.readObject(Unknown Source) ~[?:?]
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:1655) ~[fastjson2-2.0.54.jar:?]
at com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter.readType(FastJsonHttpMessageConverter.java:111) ~[fastjson2-extension-spring6-2.0.54.jar:?]
at com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter.read(FastJsonHttpMessageConverter.java:80) ~[fastjson2-extension-spring6-2.0.54.jar:?]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:184) ~[spring-webmvc-6.1.15.jar:6.1.15]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:161) ~[spring-webmvc-6.1.15.jar:6.1.15]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:135) ~[spring-webmvc-6.1.15.jar:6.1.15]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122) ~[spring-web-6.1.15.jar:6.1.15]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:224) ~[spring-web-6.1.15.jar:6.1.15]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:178) ~[spring-web-6.1.15.jar:6.1.15]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118) ~[spring-webmvc-6.1.15.jar:6.1.15]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:926) ~[spring-webmvc-6.1.15.jar:6.1.15]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:831) ~[spring-webmvc-6.1.15.jar:6.1.15]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-6.1.15.jar:6.1.15]
...
... 145 more
```
### 期待的正确结果
*@JSONField(format="xxxxx") 对http请求对象的LocalDateTime字段生效!*
Contributor guide
Research direction
Start with JSONReader.readLocalDateTime and ObjectReaderImplLocalDateTime.readObject from the stack trace, then inspect FastJsonHttpMessageConverter.readType with the default date format. Reproduce the request using @JSONField(format = "yyyy-MM-dd HH:mm:ss") on a LocalDateTime field while the converter uses milliseconds. Done means the annotated request value parses successfully without requiring the converter-wide format to match.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100