Skip to content

feat(framework,actuator,common): replace fastjson with jackson#6701

Open
halibobo1205 wants to merge 9 commits intotronprotocol:developfrom
halibobo1205:feat/jackjson
Open

feat(framework,actuator,common): replace fastjson with jackson#6701
halibobo1205 wants to merge 9 commits intotronprotocol:developfrom
halibobo1205:feat/jackjson

Conversation

@halibobo1205
Copy link
Copy Markdown
Collaborator

@halibobo1205 halibobo1205 commented Apr 23, 2026

Summary

Replace com.alibaba:fastjson with Jackson-backed drop-in wrappers (org.tron.json.{JSON, JSONObject, JSONArray, JSONException}). No external API changes — all HTTP and JSON-RPC responses remain identical.

Motivation

  • Fastjson 1.2.83 is EOL with 20+ CVEs including critical RCE
  • Upgrade jackson-databind 2.18.3 → 2.18.6 (GHSA-72hv-8253-57qq)
  • Unify JSON handling (previously split between Jackson and Fastjson)

Core changes

(common):

  • Add org.tron.json wrappers backed by a shared ObjectMapper
  • Remove fastjson from common/build.gradle
  • Expose maxNestingDepth / maxTokenCount on CommonParameter and NodeConfig.HttpConfig, with defaults 100 / 100_000 in reference.conf

(framework): HTTP & servlet changes

  • Swap imports from com.alibaba.fastjsonorg.tron.json across all HTTP servlets, JSON-RPC layer, and event/log parsers

Configuration

Two new node.http keys (defaults shown):

node {
  http {
    maxNestingDepth = 100      # Jackson default 1000
    maxTokenCount   = 100000   # Jackson default Long.MAX_VALUE
  }
}

Beyond either ceiling, parsing fails with StreamConstraintsException before any business logic runs. Defaults are sized to comfortably accommodate every legitimate java-tron HTTP payload.

Build:

  • Update Jackson to 2.18.6
  • Remove fastjson

close #6607

Comment thread common/src/main/java/org/tron/json/JSON.java
Comment thread actuator/src/main/java/org/tron/core/vm/trace/ProgramTrace.java
Comment thread common/src/main/java/org/tron/json/JSON.java
Comment thread framework/src/main/java/org/tron/core/services/http/Util.java
Comment thread common/src/main/java/org/tron/common/utils/JsonUtil.java
@yanghang8612
Copy link
Copy Markdown
Collaborator

Direction is right — fastjson 1.2.83 has been a long-standing security overhang, and consolidating on Jackson + a thin wrapper is the obvious move. Waiting on the MUST items @lxcmyf and @waynercheung raised before LGTM.

One additional question worth pinning down in the PR description: after this change, are there any remaining com.alibaba.fastjson imports reachable anywhere in the tree — or does this fully retire the dependency? The diff summary doesn't show the build.gradle side, and a grep -r 'com.alibaba.fastjson' --include='*.java' result in the PR body would make the "no more fastjson" claim explicit and let dependency scanners (GHSA, Snyk) close the finding cleanly.

Also worth a sentence in the PR description on hot-path performance posture: fastjson 1.2.x has a historically-fast parse path, and Jackson has different characteristics under LargeJsonPayload + /wallet/* throughput. If there's even a rough benchmark for DeployContractServlet / TriggerSmartContractServlet JSON-decode latency pre/post, that closes the loop on "drop-in" covering both correctness and perf.

@halibobo1205
Copy link
Copy Markdown
Collaborator Author

@yanghang8612
Fastjson fully retired:
Yes. The fastjson dependency has been removed from build.gradle (diff). If any com.alibaba.fastjson import remained, the build would fail at compile time — so a passing CI already proves zero remaining references.

Performance:
The JSON parsing hot path for /wallet/* endpoints goes through JsonFormat.java (a custom protobuf-to-JSON serializer/parser with its own Tokenizer), not through the Jackson ObjectMapper. Jackson is only used for lightweight operations: extracting a few fields (visible, type, value, etc.) from the top-level request JSON. The actual heavy lifting — protobuf message construction and field-by-field parsing — is handled by JsonFormat.merge(), which is unchanged in this PR. So there is no meaningful parse-latency delta on the hot path. Performance benchmarks will be added as a follow-up.

Comment thread common/src/main/java/org/tron/json/JSONObject.java
Comment thread common/src/main/java/org/tron/json/TypeUtils.java
Comment thread common/src/main/java/org/tron/json/TypeUtils.java
Comment thread common/src/main/java/org/tron/json/TypeUtils.java
Comment thread common/src/main/java/org/tron/json/TypeUtils.java
Comment thread common/src/main/java/org/tron/json/TypeUtils.java
Replace `com.alibaba:fastjson` with Jackson-backed drop-in
wrappers (`org.tron.json.{JSON, JSONObject, JSONArray, JSONException}`).
No external API changes — all HTTP and JSON-RPC responses remain identical.

Motivation:
- Fastjson 1.2.83 is EOL with 20+ CVEs including critical RCE
- Upgrade jackson-databind 2.18.3 → 2.18.6 (GHSA-72hv-8253-57qq)
- Unify JSON handling (previously split between Jackson and Fastjson)

Core changes (common):
- Add org.tron.json wrappers backed by a shared ObjectMapper
- Remove fastjson from common/build.gradle

HTTP & servlet changes (framework):
- Swap imports from com.alibaba.fastjson → org.tron.json across
all HTTP servlets, JSON-RPC layer, and event/log parsers

Test changes:
- Add BaseHttpTest base class for servlet test lifecycle

Build:
- Update jackson to 2.18.6
- Remove fastjson

close tronprotocol#6607
@halibobo1205 halibobo1205 requested a review from xxo1shine April 28, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:flaky topic:api rpc/http related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Replace fastjson with Jackson

6 participants