Skip to content

feat: add fastjson2-extension-vertx module#4002

Open
jujn wants to merge 9 commits intoalibaba:mainfrom
jujn:feat_3994
Open

feat: add fastjson2-extension-vertx module#4002
jujn wants to merge 9 commits intoalibaba:mainfrom
jujn:feat_3994

Conversation

@jujn
Copy link
Collaborator

@jujn jujn commented Mar 1, 2026

What this PR does / why we need it?

功能概述
新增对 Vert.x 5 的原生支持。基于 Vert.x JSON SPI 机制 (io.vertx.core.spi.json.JsonFactory) 提供 Fastjson2 的底层实现,允许用户平滑替换 Vert.x 默认的 Jackson 解析引擎。

整合工作

  • 引擎替换:对齐 Vert.x 5 官方内置 io.vertx.core.json.jackson 包的核心逻辑,提供针对 JsonObject、JsonArray、Buffer 等 Vert.x 专用类型的 Fastjson2 编解码实现。
  • 测试覆盖:移植并适配 Vert.x 官方内置的 JSON 测试套件,确保核心功能的兼容性(跳过个位数测试用例,即在测试类中进行注释,详见下面“兼容性说明”);并加入新的测试来检验 Fastjson2 与 Jackson 行为对齐(CodecAlignmentTest)
  • 性能验证:在 Vert.x 官方内置 JSON Benchmark 中集成 Fastjson2 实现,提供性能对比测试参考(测试 JSON 数据也来自官方)。

兼容性说明
当前实现已对齐 Vert.x 的绝大部分标准行为。受限于 Fastjson2 与 Jackson 底层解析架构的固有差异,少数边界场景(如容错处理、格式化输出等)可能与默认行为存在微小差异。

@jujn jujn marked this pull request as ready for review March 9, 2026 09:32
@jujn
Copy link
Collaborator Author

jujn commented Mar 9, 2026

@wenshao
根据 vertx 官方 Benchmark 测试类和测试数据(small_bench.jsonwide_bench.jsondeep_bench.json),我本地 win10 jdk17 测试,性能对比数据如下(Databind 指 Jackson 的 pojo 版本):

点击查看
反序列化:
Benchmark                                  Mode  Cnt    Score    Error   Units
JsonDecodeBenchmark.deepBufferFastjson2   thrpt   10    0.096 ±  0.002  ops/ms
JsonDecodeBenchmark.deepBufferJackson     thrpt   10    0.096 ±  0.002  ops/ms
JsonDecodeBenchmark.deepStringDatabind    thrpt   10    0.102 ±  0.002  ops/ms
JsonDecodeBenchmark.deepStringFastjson2   thrpt   10    0.097 ±  0.002  ops/ms
JsonDecodeBenchmark.deepStringJackson     thrpt   10    0.097 ±  0.002  ops/ms
JsonDecodeBenchmark.smallBufferFastjson2  thrpt   10  102.430 ±  5.903  ops/ms
JsonDecodeBenchmark.smallBufferJackson    thrpt   10   98.043 ±  7.338  ops/ms
JsonDecodeBenchmark.smallStringDatabind   thrpt   10   72.815 ±  5.748  ops/ms
JsonDecodeBenchmark.smallStringFastjson2  thrpt   10  110.590 ±  9.142  ops/ms
JsonDecodeBenchmark.smallStringJackson    thrpt   10  103.262 ± 16.854  ops/ms
JsonDecodeBenchmark.wideBufferFastjson2   thrpt   10    0.880 ±  0.076  ops/ms
JsonDecodeBenchmark.wideBufferJackson     thrpt   10    0.999 ±  0.063  ops/ms
JsonDecodeBenchmark.wideStringDatabind    thrpt   10    0.744 ±  0.090  ops/ms
JsonDecodeBenchmark.wideStringFastjson2   thrpt   10    1.017 ±  0.041  ops/ms
JsonDecodeBenchmark.wideStringJackson     thrpt   10    0.958 ±  0.067  ops/ms
序列化:
Benchmark                                 Mode  Cnt     Score     Error  Units
JsonEncodeBenchmark.deepBufferDatabind    avgt   10  3867.923 ± 703.526  us/op
JsonEncodeBenchmark.deepBufferFastjson2   avgt   10  4966.555 ± 396.139  us/op
JsonEncodeBenchmark.deepBufferJackson     avgt   10  3923.064 ± 187.208  us/op
JsonEncodeBenchmark.deepStringDatabind    avgt   10  4879.711 ± 127.691  us/op
JsonEncodeBenchmark.deepStringFastjson2   avgt   10  3618.457 ± 112.852  us/op
JsonEncodeBenchmark.deepStringJackson     avgt   10  5476.450 ± 222.686  us/op
JsonEncodeBenchmark.smallBufferDatabind   avgt   10    11.080 ±   0.128  us/op
JsonEncodeBenchmark.smallBufferFastjson2  avgt   10     6.181 ±   0.217  us/op
JsonEncodeBenchmark.smallBufferJackson    avgt   10    13.372 ±   0.231  us/op
JsonEncodeBenchmark.smallStringDatabind   avgt   10     6.967 ±   0.361  us/op
JsonEncodeBenchmark.smallStringFastjson2  avgt   10     5.196 ±   0.184  us/op
JsonEncodeBenchmark.smallStringJackson    avgt   10     9.925 ±   0.262  us/op
JsonEncodeBenchmark.tinyBufferFastjson2   avgt   10     0.149 ±   0.005  us/op
JsonEncodeBenchmark.tinyBufferJackson     avgt   10     0.403 ±   0.012  us/op
JsonEncodeBenchmark.wideBufferDatabind    avgt   10   682.610 ±  19.871  us/op
JsonEncodeBenchmark.wideBufferFastjson2   avgt   10  1136.372 ±  24.996  us/op
JsonEncodeBenchmark.wideBufferJackson     avgt   10   755.716 ±  23.177  us/op
JsonEncodeBenchmark.wideStringDatabind    avgt   10   921.412 ±  23.148  us/op
JsonEncodeBenchmark.wideStringFastjson2   avgt   10   803.171 ±  13.441  us/op
JsonEncodeBenchmark.wideStringJackson     avgt   10   984.710 ±  25.273  us/op

专业的事情需要专业的人来做,我不太懂性能优化,所以搭好了“脚手架”,希望您后续有时间可以进一步优化。

@wenshao
Copy link
Member

wenshao commented Mar 9, 2026

构建通不过?

Comment on lines -454 to +455
boolean fieldBased = (writerFieldFeatures & JSONWriter.Feature.FieldBased.mask) != 0;
boolean fieldBased = ((writerFieldFeatures & JSONWriter.Feature.FieldBased.mask) != 0 && !objectClass.isInterface())
|| !beanInfo.alphabetic;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里修复 creator=reflect 时,设置 alphabetic=false(序列化对象字段的输出顺序)不生效的问题;同时调整了其它地方,与 creator=asm 保持一致

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.

2 participants