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] JSONB.toBytes with org.joda.time.DateTime #2563

Closed
Cooper-Zhong opened this issue May 11, 2024 · 3 comments
Closed

[BUG] JSONB.toBytes with org.joda.time.DateTime #2563

Cooper-Zhong opened this issue May 11, 2024 · 3 comments
Assignees
Labels
bug Something isn't working fixed
Milestone

Comments

@Cooper-Zhong
Copy link
Contributor

问题描述

JSONB.toBytes时无法处理org.joda.time.DateTime字段

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson2 2.0.50-SNAPSHOT]

重现步骤

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONB;
import org.joda.time.DateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MutatedIssue2332_567 {

    DateTime nowD = new DateTime(2018, 7, 14, 12, 13, 14, 0);

    @Test
    public void mutatedTest0() {
        Bean0 entity = new Bean0();
        entity.setNow(nowD);

        String json = JSON.toJSONString(entity);
        Bean0 bean0 = JSON.parseObject(json, Bean0.class);
        assertEquals(entity.now, bean0.now);
    }

    @Test
    public void mutatedTest1() {
        Bean0 entity = new Bean0();
        entity.setNow(nowD);

        byte[] jsonbBytes = JSONB.toBytes(entity);
        Bean0 bean0 = JSONB.parseObject(jsonbBytes, Bean0.class);
        assertEquals(entity.now, bean0.now);
    }


    @Data
    public static class Bean0 {
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private DateTime now;
    }

}

相关日志输出

java.lang.ClassCastException: class org.joda.time.DateTime cannot be cast to class java.time.ZonedDateTime (org.joda.time.DateTime is in unnamed module of loader 'app'; java.time.ZonedDateTime is in module java.base of loader 'bootstrap')
at com.alibaba.fastjson2.writer.ObjectWriterImplZonedDateTime.writeJSONB(ObjectWriterImplZonedDateTime.java:31)
at com.alibaba.fastjson2.writer.OWG_1_1_Bean0.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.JSONB.toBytes(JSONB.java:1155)
at MutatedIssue2332_567.mutatedTest1(MutatedIssue2332_567.java:32)

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label May 11, 2024
@wenshao wenshao added this to the 2.0.50 milestone May 11, 2024
@wenshao wenshao self-assigned this May 11, 2024
@wenshao wenshao added the fixed label May 11, 2024
@wenshao
Copy link
Member

wenshao commented May 11, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.50-SNAPSHOT/
问题已修复,请帮忙用2.0.50-SNAPSHOT版本验证下

@Cooper-Zhong
Copy link
Contributor Author

验证已修复,辛苦wenshao

@wenshao
Copy link
Member

wenshao commented May 12, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.50
2.0.50已发布,请用新版本

@wenshao wenshao closed this as completed May 12, 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 fixed
Projects
None yet
Development

No branches or pull requests

2 participants