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] 日期时间格式化注解,对 java.time.OffsetDateTime 失效 #2005

Closed
ldcsaa opened this issue Nov 8, 2023 · 4 comments
Closed
Assignees
Labels
bug Something isn't working fixed
Milestone

Comments

@ldcsaa
Copy link

ldcsaa commented Nov 8, 2023

问题描述

日期时间格式化注解,@JSONField(format = "xxx") @JsonFormat(pattern = "xxx") java.time.OffsetDateTime类型属性都失效。
属性类型改为 java.time.ZonedDateTime则生效。

环境信息

  • OS信息: [e.g.:Win10]
  • JDK信息: [e.g.:jdk 17]
  • 版本信息:[e.g.:Fastjson-2 0.41]

重现步骤

定义Java Bean

@Getter
@Setter
public static class Item
{
	private String jobNumber;
	/* 下列两种注解,对 updateTime 都失效,除非把 updateTime 改为 ZonedDateTime 类型 */
	//@JSONField(format = "yyyy-MM-dd HH:mm")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
	private OffsetDateTime updateTime;
}

调用 JSON.toJSONString(bean),永远以默认格式"yyyy-MM-dd'T'HH:mm:ss.SSSXXX输出

{"jobNumber":"ssss","updateTime":"2023-11-08T14:56:00.654744300+08:00"}

期待的正确结果

可以通过@JSONField(format = "")@JsonFormat(pattern = "")指定日期序列化格式

@ldcsaa ldcsaa added the bug Something isn't working label Nov 8, 2023
@yanxutao89 yanxutao89 self-assigned this Nov 8, 2023
yanxutao89 added a commit to yanxutao89/fastjson2 that referenced this issue Nov 8, 2023
@wenshao wenshao added this to the 2.0.43 milestone Nov 8, 2023
@wenshao
Copy link
Member

wenshao commented Nov 11, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.43-SNAPSHOT/
问题已修复,请帮忙用2.0.43-SNAPSHOT版本验证,2.0.43正式版本预计在12月3日前发布

@wenshao wenshao added the fixed label Nov 12, 2023
@ldcsaa
Copy link
Author

ldcsaa commented Nov 13, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.43-SNAPSHOT/ 问题已修复,请帮忙用2.0.43-SNAPSHOT版本验证,2.0.43正式版本预计在12月3日前发布

要等大半个月~~??

@wenshao
Copy link
Member

wenshao commented Nov 13, 2023

最近发布的节奏是每个月初第一个周末发布新版本

@wenshao
Copy link
Member

wenshao commented Dec 3, 2023

@wenshao wenshao closed this as completed Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants