Skip to content

feat(java): add fory json serialization#3784

Open
chaokunyang wants to merge 7 commits into
apache:mainfrom
chaokunyang:fory_java_json
Open

feat(java): add fory json serialization#3784
chaokunyang wants to merge 7 commits into
apache:mainfrom
chaokunyang:fory_java_json

Conversation

@chaokunyang

@chaokunyang chaokunyang commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Why?

Fory Java needs a first-class JSON serialization path that keeps Fory's field-based data model and TypeRef-aware type resolution while providing competitive parse and write throughput for String and UTF-8 inputs.

What does this PR do?

  • Adds the standalone fory-json Java module and wires it into the Java build.
  • Adds public JSON APIs including ForyJson, ForyJsonBuilder, JSONObject, JSONArray, ForyJsonException, and @JsonIgnore.
  • Implements field-based codecs for objects, scalars, arrays, collections, and maps, including generic TypeRef root reads.
  • Adds generated object codecs plus layout-specific readers and writers for Latin1 strings, UTF16 strings, and UTF-8 bytes.
  • Adds JSON metadata, resolver, reader, writer, codegen, benchmark, and test coverage for the new module.
  • Adds the small core codegen, memory, field-access, and string-layout hooks needed by the JSON module.

This is still in the early stage, more works will be submitted in follow-up prs.

Related issues

None.

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

This adds the new Java fory-json module and public JSON APIs. It does not change the Fory binary or xlang wire protocol.

Benchmark

Latest JDK21 single-thread Eishay gate after optimization, compared against same-run registered Fory binary lanes:

  • JSON parse String: 95.2% of registered Fory binary parse
  • JSON parse UTF8: 93.7% of registered Fory binary parse
  • JSON write String: 92.2% of registered Fory binary write
  • JSON write UTF8: 90.7% of registered Fory binary write

JMH Perf result:

  • EishayParseString.foryJson thrpt 3 6925519.766 ± 423432.614 ops/s
  • EishayWriteString.foryJson thrpt 3 8974737.287 ± 681622.845 ops/s

Add the standalone fory-json module with field-based JSON codecs, generated object codecs, layout-specific readers/writers, TypeRef reads, JSON object/array support, benchmarks, and tests.\n\nLatest JDK21 single-thread Eishay gate after optimization:\n- JSON parse String: 95.2% of registered Fory binary parse\n- JSON parse UTF8: 93.7% of registered Fory binary parse\n- JSON write String: 92.2% of registered Fory binary write\n- JSON write UTF8: 90.7% of registered Fory binary write
@chaokunyang chaokunyang requested review from pandalee99 and urlyy June 24, 2026 01:49
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