Skip to content

refactor(framework): replace fastjson with jackson#120

Open
halibobo1205 wants to merge 10 commits intodevelopfrom
feat/jackjson2
Open

refactor(framework): replace fastjson with jackson#120
halibobo1205 wants to merge 10 commits intodevelopfrom
feat/jackjson2

Conversation

@halibobo1205
Copy link
Copy Markdown
Owner

@halibobo1205 halibobo1205 commented Apr 4, 2026

User description

Remove the Fastjson dependency entirely and replace it with Jackson-backed drop-in wrappers (JSON, JSONObject, JSONArray, JSONException) that preserve the same public API surface.

Motivation:

  • Fastjson has a history of critical CVEs and is no longer actively maintained for 1.x
  • Jackson-databind 2.18.6 addresses CVE GHSA-72hv-8253-57qq

Core changes (common module):

  • Add org.tron.json.{JSON, JSONObject, JSONArray, JSONException} wrappers backed by a shared Jackson ObjectMapper configured to match Fastjson 1.x parsing/serialization defaults:
    • Unquoted field names and single-quoted strings (lenient parsing)
    • BigDecimal for floats, case-insensitive property matching
    • Null fields omitted (matches Fastjson default)
  • Type-safe accessors: getBoolean/getLong/getDouble/getIntValue/ getLongValue/getBigDecimal throw JSONException on invalid text instead of silently returning 0/false
  • parseObject(String) guards against ClassCastException on non-object JSON roots; parseArray handles whitespace-only input
  • parseObject(String, Class) delegates to parseObject/parseArray for wrapper types to avoid silent field loss via ObjectMapper
  • Upgrade jackson-databind 2.18.3 → 2.18.6

HTTP servlet changes (framework module):

  • Swap import from com.alibaba.fastjson → org.tron.json` across all HTTP API servlets, JSON-RPC layer, and event/log parsers
  • No changes to request/response JSON structure — existing API contracts are preserved

Test changes:

  • Add BaseHttpTest base class managing Args lifecycle, Wallet mock, MINIMAL_TX constant, and request/response factory methods (postRequest, getRequest, newResponse)
  • 44 servlet test classes refactored to extend BaseHttpTest, eliminating ~1400 lines of duplicated boilerplate
  • Strengthen weak assertNotNull checks to content-based assertions: assertTrue(contains("raw_data")) for transaction servlets, assertTrue(contains("blockID")) for block queries, etc.
  • Add Mockito verify for wallet service calls in query servlets to catch request-to-service mapping regressions
  • Fix test environment: initialize Args from config-test.conf (maxMessageSize) and use MINIMAL_TX with raw_data to prevent NPE in Util.printCreateTransaction
  • Add JsonCompatibilityFuzzTest: 500-round fuzz covering round-trip serialization, BigDecimal/BigInteger precision, deep nesting, unicode, and boundary values
  • Use SecureRandom for fuzz test randomization

Build:

  • Remove fastjson from common/build.gradle dependencies
  • Update gradle/verification-metadata.xml for jackson 2.18.6

CodeAnt-AI Description

Replace Fastjson with Jackson-backed JSON handling and tighten test/CI coverage

What Changed

  • Replaced Fastjson usage across HTTP, JSON-RPC, event parsing, and shared utilities with new Jackson-backed JSON wrappers, while keeping existing request and response formats intact.
  • Added safer JSON parsing and value access so invalid text now fails clearly instead of returning silent default values; empty or blank JSON inputs are handled consistently.
  • Updated VM trace serialization to use a single field-based JSON output path, and fixed genesis block timestamp validation so negative values are rejected with a clear error.
  • Expanded and refactored servlet tests to cover the new JSON behavior and verify service calls, and added new CI steps for reviewer assignment and coverage checks.

Impact

✅ Safer API JSON parsing
✅ Clearer validation errors for invalid inputs
✅ Fewer missed regressions in HTTP endpoints

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 4, 2026

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codeant-ai codeant-ai bot added the size:XXL This PR changes 1000+ lines, ignoring generated files label Apr 4, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 4, 2026

CodeAnt AI finished reviewing your PR.

halibobo1205 added a commit that referenced this pull request Apr 4, 2026
…erministic fuzz

- Use exact token_id/sell_token_id/buy_token_id byte assertions instead
  of non-empty checks in Exchange and Market servlet tests
- Add account_id byte assertion in SetAccountIdServletTest
- Switch fuzz test from non-deterministic SecureRandom to seeded Random
  for reproducible CI failures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@halibobo1205
Copy link
Copy Markdown
Owner Author

@CodeAnt-AI: review

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 4, 2026

CodeAnt AI is running the review.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:XXL This PR changes 1000+ lines, ignoring generated files and removed size:XXL This PR changes 1000+ lines, ignoring generated files labels Apr 4, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 4, 2026

Sequence Diagram

This PR replaces Fastjson with Jackson-backed JSON, JSONObject, and JSONArray wrappers and wires all HTTP servlets to use them, so request bodies are parsed and responses serialized via a shared, safely-configured ObjectMapper while preserving existing API contracts.

sequenceDiagram
    participant Client
    participant HttpServlet
    participant JSONWrapper
    participant Wallet
    participant Util

    Client->>HttpServlet: POST transaction request (JSON body)
    HttpServlet->>JSONWrapper: parseObject(requestBody) to JSONObject
    HttpServlet->>Wallet: createTransactionCapsule(built from JSONObject fields)
    Wallet-->>HttpServlet: Transaction object
    HttpServlet->>Util: Serialize Transaction to JSON via JSON/JSONObject/JSONArray
    Util-->>Client: 200 OK with transaction JSON response
Loading

Generated by CodeAnt AI

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 4, 2026

CodeAnt AI finished running the review.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@halibobo1205
Copy link
Copy Markdown
Owner Author

@codex: review

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Sunny6889 and others added 5 commits April 6, 2026 10:13
opt(common): GenesisBlock timestamp valid message error
Remove the Fastjson dependency entirely and replace it with
Jackson-backed drop-in wrappers (JSON, JSONObject, JSONArray,
JSONException) that preserve the same public API surface.

Motivation:
- Fastjson has a history of critical CVEs and is no longer
  actively maintained for 1.x
- Jackson-databind 2.18.6 addresses CVE GHSA-72hv-8253-57qq

Core changes (common module):
- Add org.tron.json.{JSON, JSONObject, JSONArray, JSONException}
  wrappers backed by a shared Jackson ObjectMapper configured to
  match Fastjson 1.x parsing/serialization defaults:
  - Unquoted field names and single-quoted strings (lenient parsing)
  - BigDecimal for floats, case-insensitive property matching
  - Null fields omitted (matches Fastjson default)
- Type-safe accessors: getBoolean/getLong/getDouble/getIntValue/
  getLongValue/getBigDecimal throw JSONException on invalid text
  instead of silently returning 0/false
- parseObject(String) guards against ClassCastException on
  non-object JSON roots; parseArray handles whitespace-only input
- parseObject(String, Class) delegates to parseObject/parseArray
  for wrapper types to avoid silent field loss via ObjectMapper
- Upgrade jackson-databind 2.18.3 → 2.18.6

HTTP servlet changes (framework module):
- Swap import from com.alibaba.fastjson → org.tron.json across all
  HTTP API servlets, JSON-RPC layer, and event/log parsers
- No changes to request/response JSON structure — existing API
  contracts are preserved

Test changes:
- Add BaseHttpTest base class managing Args lifecycle, Wallet mock,
  MINIMAL_TX constant, and request/response factory methods
  (postRequest, getRequest, newResponse)
- 44 servlet test classes refactored to extend BaseHttpTest,
  eliminating ~1400 lines of duplicated boilerplate
- Strengthen weak assertNotNull checks to content-based assertions:
  assertTrue(contains("raw_data")) for transaction servlets,
  assertTrue(contains("blockID")) for block queries, etc.
- Add Mockito verify for wallet service calls in query servlets
  to catch request-to-service mapping regressions
- Fix test environment: initialize Args from config-test.conf
  (maxMessageSize) and use MINIMAL_TX with raw_data to prevent
  NPE in Util.printCreateTransaction
- Add JsonCompatibilityFuzzTest: 500-round fuzz covering
  round-trip serialization, BigDecimal/BigInteger precision,
  deep nesting, unicode, and boundary values
- Use SecureRandom for fuzz test randomization

Build:
- Remove fastjson from common/build.gradle dependencies
- Update gradle/verification-metadata.xml for jackson 2.18.6

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: codeant-ai[bot] <151821869+codeant-ai[bot]@users.noreply.github.com>
Co-Authored-By: codex <codex@openai.com>
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 9, 2026

CodeAnt AI is running Incremental review


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:XXL This PR changes 1000+ lines, ignoring generated files and removed size:XXL This PR changes 1000+ lines, ignoring generated files labels Apr 9, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 9, 2026

CodeAnt AI Incremental review completed.

@halibobo1205
Copy link
Copy Markdown
Owner Author

@codex: review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4ef086465c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
// Fastjson smart-match: field names are matched ignoring case/underscores by default
// (DisableFieldSmartMatch is OFF by default → smart match ON)
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Enable underscore smart-match for class deserialization

JSON.parseObject(text, clazz) is documented as Fastjson-compatible smart matching, but the mapper only enables case-insensitive properties here; it does not map snake_case JSON keys to camelCase fields. Because FAIL_ON_UNKNOWN_PROPERTIES is disabled, payloads like {"fee_limit":...} are silently dropped instead of populating feeLimit, which can produce incorrect default values without any error in downstream request/object binding.

Useful? React with 👍 / 👎.

* Drop-in replacement for {@code com.alibaba.fastjson.JSONObject}.
* Swap the import line; no other source changes required for basic usages.
*/
public class JSONObject {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Implement Map contract on JSONObject wrapper

This wrapper is declared as a drop-in replacement for Fastjson JSONObject, but it no longer implements Map<String, Object>. Any caller that follows the advertised “swap import line” migration and passes JSONObject to APIs expecting Map, or relies on Map methods/typing, will fail to compile (or require invasive rewrites), so the replacement is not source-compatible for common usages.

Useful? React with 👍 / 👎.

* Drop-in replacement for {@code com.alibaba.fastjson.JSONArray}.
* Swap the import line; no other source changes required for basic usages.
*/
public class JSONArray implements Iterable<Object> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Implement List contract on JSONArray wrapper

Fastjson JSONArray is widely used as a List<Object>, but this replacement only implements Iterable<Object>. Existing call sites that use List-typed parameters/utilities (e.g., collections helpers, interface-based method signatures) are no longer compatible after an import swap, which breaks the stated drop-in migration path and forces non-trivial refactors.

Useful? React with 👍 / 👎.

…appers

Remove methods that were implemented for Fastjson API compatibility but
have zero call sites in the java-tron codebase:

JSONObject: getDouble(), toMap(), parseArray() (proxy)
JSONArray: isEmpty(), getJSONArray(int), getBoolean(int), toJavaList(),
           add(JSONArray), add(String), add(Object)

Also fix EventParserJsonTest to call JSONArray.parseArray() directly
and clean up 22 corresponding test methods in JsonCompatibilityFuzzTest.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 14, 2026

CodeAnt AI is running Incremental review


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:XXL This PR changes 1000+ lines, ignoring generated files and removed size:XXL This PR changes 1000+ lines, ignoring generated files labels Apr 14, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 14, 2026

CodeAnt AI Incremental review completed.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5227cca3d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +328 to +330
if (value == null) {
node.remove(key);
} else {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve null-valued keys in JSONObject.put

The new wrapper removes a field when put(..., null) is called, but Fastjson JSONObject.put keeps the key with a JSON null value. This causes silent data loss: containsKey flips from true to false and serialized payloads drop explicitly-null fields (e.g. {"address":null} becomes {}), which can change behavior for callers that intentionally send null to represent an explicit unset value. Use putNull-style assignment instead of removing the key in null branches.

Useful? React with 👍 / 👎.

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

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants