Skip to content

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

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

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

Conversation

@halibobo1205
Copy link
Copy Markdown
Collaborator

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

(framework): HTTP & servlet changes

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

Build:

  • Update Jackson to 2.18.6
  • Remove fastjson

close #6607

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
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.

}

public JSONObject put(String key, Integer value) {
if (value == null) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[SHOULD] The following logic is used in multiple places and can be encapsulated into a function.

    if (value == null) {
      node.remove(key);
    } else {
      node.put(key, value);
    }
    return this;

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
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