Skip to content

fix: restore fastjson 1.x behavior of ignoring unknown keys in toJavaObject - #7861

Open
wylovelyi wants to merge 1 commit into
alibaba:mainfrom
wylovelyi:fix/issue-7782
Open

wylovelyi wants to merge 1 commit into
alibaba:mainfrom
wylovelyi:fix/issue-7782

Conversation

@wylovelyi

Copy link
Copy Markdown

Summary

In the fastjson1-compatible module, JSON.toJavaObject(json, clazz) delegates to ObjectReader.createInstance. When the source JSONObject contains an extra field whose key is not a property of the target bean (e.g. /*), createInstance throws IntrospectionException on some JDK/architecture combinations (reported on ARM aarch64 JDK8), while x86-64 JDK8 silently ignores it. fastjson 1.2.83 caught this exception internally; the 2.0.x compat layer dropped that logic during the port, causing inconsistent cross-platform behavior (see #7782).

Root cause

JSONObject.toJavaObject(Class) calls objectReader.createInstance(this, ...) without the defensive IntrospectionException handling that fastjson 1.2.83 had.

Fix

Wrap the createInstance call in a try/catch. On failure, fall back to a property-by-property copy that only sets the target bean's own writable properties via java.beans.Introspector, dropping unknown keys — restoring the 1.x behavior consistently on all platforms.

Test

Added Issue7782 regression test: a JSONObject with a normal name field plus an extra /* field is converted to the target bean; the bean is produced and name is correctly populated.

Fixes #7782

…Object

In the fastjson1-compatible module, JSON.toJavaObject(json, clazz) delegates to ObjectReader.createInstance. On some JDK/architecture combinations (e.g. ARM aarch64 JDK8) this throws IntrospectionException when the source JSONObject contains an extra field whose key is not a property of the target bean (e.g. "/*"), while x86-64 JDK8 silently ignores it. fastjson 1.2.83 caught this exception internally; the 2.0.x compat layer omitted that logic during porting.

Catch the exception and fall back to a property-by-property copy that only sets the target bean's own properties and drops unknown keys, restoring consistent cross-platform behavior.

Fixes alibaba#7782
@CLAassistant

CLAassistant commented Sep 10, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

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

[BUG] JSON.toJavaObject跨平台行为不一致,特殊名称的多余字段在ARM JDK8抛出IntrospectionException

2 participants