Skip to content

Conversation

@mengnankkkk
Copy link
Contributor

@mengnankkkk mengnankkkk commented Jan 5, 2026

What this PR does / why we need it?

增加Year、YearMonth、MonthDay 的支持和一部分测试,还缺少什么可以补充下,谢谢🙏了呀
但是貌似Jackson不支持HijrahDate这种,其他是正常的,但其他的肯定是优于Jackson的性能的

Summary of your change

Close #3857

点击查看测试代码
public class TimeBenchmark {

    @State(Scope.Benchmark)
    public static class BenchmarkState {
        ObjectMapper jacksonMapper;
        TimePojo pojo;
        byte[] jsonBytes;

        @Setup(Level.Trial)
        public void setup() {
            jacksonMapper = JsonMapper.builder().build();

            LocalDate baseDate = LocalDate.of(2026, 1, 6);
            pojo = new TimePojo(
                    1,
                    "alpha",
                    Year.of(2026),
                    YearMonth.of(2026, 1),
                    MonthDay.of(1, 6),
                    JapaneseDate.from(baseDate),
                    MinguoDate.from(baseDate),
                    ThaiBuddhistDate.from(baseDate)
            );

            String json = "{\"id\":1,\"name\":\"alpha\",\"year\":\"2026\",\"yearMonth\":\"2026-01\",\"monthDay\":\"--01-06\",\"japaneseDate\":\"Japanese Reiwa 8-01-06\",\"minguoDate\":\"Minguo ROC 115-01-06\",\"thaiBuddhistDate\":\"ThaiBuddhist BE 2569-01-06\"}";
            jsonBytes = json.getBytes(StandardCharsets.UTF_8);
        }
    }

    @Benchmark
    public void fastjson2Serialize(BenchmarkState state, Blackhole bh) {
        bh.consume(JSON.toJSONBytes(state.pojo));
    }

    @Benchmark
    public void fastjson2Deserialize(BenchmarkState state, Blackhole bh) {
        bh.consume(JSON.parseObject(state.jsonBytes, TimePojo.class));
    }

    @Benchmark
    public void jackson3Serialize(BenchmarkState state, Blackhole bh) throws Exception {
        bh.consume(state.jacksonMapper.writeValueAsBytes(state.pojo));
    }

    @Benchmark
    public void jackson3Deserialize(BenchmarkState state, Blackhole bh) throws Exception {
        bh.consume(state.jacksonMapper.readValue(state.jsonBytes, TimePojo.class));
    }

    public static class TimePojo {
        public int id;
        public String name;
        public Year year;
        public YearMonth yearMonth;
        public MonthDay monthDay;
        public JapaneseDate japaneseDate;
        public MinguoDate minguoDate;
        public ThaiBuddhistDate thaiBuddhistDate;

        public TimePojo() {
        }

        public TimePojo(int id, String name, Year year, YearMonth yearMonth, MonthDay monthDay,
                        JapaneseDate japaneseDate,
                        MinguoDate minguoDate, ThaiBuddhistDate thaiBuddhistDate) {
            this.id = id;
            this.name = name;
            this.year = year;
            this.yearMonth = yearMonth;
            this.monthDay = monthDay;
            this.japaneseDate = japaneseDate;
            this.minguoDate = minguoDate;
            this.thaiBuddhistDate = thaiBuddhistDate;
        }
    }
}
Jackson依赖版本 tools.jackson.core jackson-databind 3.0.2

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@ban-xiu
Copy link

ban-xiu commented Jan 5, 2026

你好,我发现好像似乎没有支持所有的time类型

@jujn
Copy link
Collaborator

jujn commented Jan 5, 2026

温老师对性能要求很高的,我觉得部分类型可能需要 ObjectReaderImplXxx ……

@mengnankkkk mengnankkkk closed this Jan 5, 2026
@mengnankkkk mengnankkkk reopened this Jan 5, 2026
@mengnankkkk mengnankkkk marked this pull request as draft January 5, 2026 15:17
@jujn
Copy link
Collaborator

jujn commented Jan 6, 2026

我觉得可以先不着急兼容所有时间类型,可以先拿已实现的几个类型跑一下 JMH BenchMark(可以和 Jackson 做下对比,也可以是其它),这样可能更容易被接受

@mengnankkkk
Copy link
Contributor Author

image

@jujn
Copy link
Collaborator

jujn commented Jan 7, 2026

👍,能否提供 benchmark 测试代码?可以用下面方式折叠起来,更方便查看

<details>
<summary>点击查看代码</summary>
……
</details>

@mengnankkkk
Copy link
Contributor Author

你好,我发现好像似乎没有支持所有的time类型

可以具体说一下还有哪些没支持吗?谢谢了!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Java8 TimeModule 支持

3 participants