Skip to content

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

Open
halibobo1205 wants to merge 1 commit intotronprotocol:developfrom
halibobo1205:feat/jackjson
Open

feat(framework,actuator,common): replace fastjson with jackson#6701
halibobo1205 wants to merge 1 commit 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
* case-insensitive {@code "null"} literal — mirroring Fastjson's lenient
* treatment of these inputs as JSON {@code null}.
*/
static boolean isNullLiteral(String text) {
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.

[MUST] Preserve unquoted NULL compatibility: {a:NULL} currently throws, but fastjson 1.2.83 accepted this and treated it as null. Since this PR claims drop-in behavior, this is a breaking compatibility regression for existing clients and should be fixed before merge.


public String asJsonString(boolean formatted) {
return serializeFieldsOnly(this, formatted);
public String asJsonString() {
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] Avoid breaking ProgramTrace.asJsonString(boolean) API: replacing it with a no-arg method introduces source/binary compatibility risk for external callers and removes compact-vs-pretty output control. Prefer keeping the original signature (or adding an overload) to preserve compatibility.

// Fastjson tolerates trailing commas (e.g. {"a":1,}) by default
.enable(JsonReadFeature.ALLOW_TRAILING_COMMA)
// Fastjson accepts NaN/Infinity as valid tokens
.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS)
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.

[MUST] Please remove this flag from the shared request parser.

This is reachable on current wallet HTTP paths, not just a theoretical Fastjson-parity issue. DeployContractServlet and TriggerSmartContractServlet read call_value, call_token_value, token_id, and fee_limit through Util.getJsonLongValue(...).

With this flag enabled, Infinity / -Infinity parse successfully, getBigDecimal(...) returns null, and those non-required fields become 0L instead of rejecting the request. Before this PR, Fastjson rejected those payloads during parse.

parameter.put("type_url", contract.getParameterOrBuilder().getTypeUrl());
JSONObject jsonContract = new JSONObject();
jsonContract.put(PARAMETER, parameter);
jsonContract.put("type", contract.getType());
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] This line controls the "type" field in every HTTP transaction JSON payload, but the new tests do not pin the exact serialized value here.

UtilMockTest#testPrintTransactionToJSON() only asserts non-null, and most servlet tests only check "no Error" / key presence. Please add an exact-output assertion that "type" remains the expected string for at least one TransferContract and one TriggerSmartContract response.


@Getter
@Setter
private JSONObject transaction;
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.

[QUESTION] TransactionJson.transaction is serialized by jsonrpc4j's own ObjectMapper, not org.tron.json.JSON.MAPPER. @JsonValue on JSONObject.unwrap() should bridge them, but I couldn't find a test that pins the on-wire bytes.

BuildTransactionTest stops at the rebuilt ContractType; JsonrpcServiceTest doesn't cover this serialization path.

Could we add one golden-output assertion for a representative buildTransaction response (transfer + trigger contract)? That's the most direct check on the "responses remain identical" claim for the JSON-RPC layer.

Comment thread common/src/main/java/org/tron/common/utils/JsonUtil.java

@Test
public void testGet() throws Exception {
MockHttpServletRequest request =
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.

[NIT] git diff --check still reports trailing whitespace here.

What about:

MockHttpServletRequest request = getRequest("visible", "true", "value",
        "TBxSocpujP6UGKV5ydXNVTDQz7fAgdmoaB");

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

Labels

topic:api rpc/http related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Replace fastjson with Jackson

5 participants