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

对OffsetDateTime类型做自定义序列化格式配置不生效 #3205

Open
AprilViolet opened this issue Dec 13, 2024 · 0 comments
Open

对OffsetDateTime类型做自定义序列化格式配置不生效 #3205

AprilViolet opened this issue Dec 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@AprilViolet
Copy link

AprilViolet commented Dec 13, 2024

问题描述

对OffsetDateTime类型做自定义序列化格式配置不生效

环境信息

  • OS信息: win11 24H2 Ryzen 9 5900X
  • JDK信息: Oracle JDK23.0.1
  • 版本信息:2.0.53

重现步骤

  • fastjson2结合springboot3中,使用 JSON.register 注册全局序列化格式无效,无论设置什么格式,最终都会变成 yyyy-MM-dd HH:mm:ss
JSON.register(OffsetDateTime.class, (jsonWriter, object, _, _, _) -> {
    if (object == null) {
        jsonWriter.writeNull();
        return;
    }
jsonWriter.writeString(TimeUtil.format((OffsetDateTime) object, "yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
  • 当删除上面的全局设置后,则恢复成默认的序列化格式
  • 但是对其他类型比如:LocalDate、LocalDateTime等设置序列化的格式是可以生效的
  • 在配置切面使用JSON.toJSONString()去打印返参的时候是可以正常使用自定义配置的格式打印,但是在请求接口中的格式就不正确

image
image

  • 切面在接口返回前打印返回结果,正常显示

image

@AprilViolet AprilViolet added the bug Something isn't working label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant