Skip to content

fix: initialize writable unwrapped map fields - #7815

Open
DarrenChangJR wants to merge 1 commit into
alibaba:mainfrom
DarrenChangJR:fix/unwrapped-null-map
Open

fix: initialize writable unwrapped map fields#7815
DarrenChangJR wants to merge 1 commit into
alibaba:mainfrom
DarrenChangJR:fix/unwrapped-null-map

Conversation

@DarrenChangJR

Copy link
Copy Markdown

What this PR does and why

Deserializing an unknown property into an unwrapped map assumes that the map is
already initialized. A writable @JSONField(unwrapped = true) map field whose
initial value is null therefore throws NullPointerException in
FieldReaderMapReadOnly.processExtra.

When the accessor supports assignment, this change creates the declared map
through the existing typed map reader, assigns it to the object, and then
stores the extra property. This preserves concrete map types and generic value
conversion. Read-only maps are not assigned.

Tests

The additions to UnwrappedTest cover:

  • text JSON and JSONB into a null Map<String, Long> field;
  • a value outside the Integer range to verify generic conversion;
  • initialization as the declared TreeMap concrete type;
  • JSONPath assignment into the initially null unwrapped map.

Validation performed:

  • focused UnwrappedTest;
  • mvn -pl core validate;
  • clean full core suite: 7,977 tests, no failures or errors;
  • external Fastjson 1.2.83 compatibility matrix: the unwrapped-map failure is
    removed and unrelated findings are unchanged.

Checklist

  • The map is created only when the property accessor is writable.
  • The declared map class and generic value type are preserved.
  • Text JSON, JSONB, and JSONPath paths are covered.
  • No public API or documentation change is required.
中文说明

修改内容和原因

反序列化未知字段到 unwrapped map 时,当前实现假设 map 已经初始化。因此,
当可写的 @JSONField(unwrapped = true) map 字段初始值为 null 时,
FieldReaderMapReadOnly.processExtra 会抛出 NullPointerException

本修改在属性可写时,通过现有的强类型 map reader 创建声明的 map 类型,
先赋值到对象,再写入额外字段。这样可以保留具体 map 类型和泛型值转换;
只读 map 不会被赋值。

测试

UnwrappedTest 新增覆盖:

  • 文本 JSON 和 JSONB 写入初始为 null 的 Map<String, Long>
  • 使用超出 Integer 范围的数值验证泛型转换;
  • 保留声明的 TreeMap 具体类型;
  • JSONPath 写入初始为 null 的 unwrapped map。

聚焦测试和 Maven validate 通过,完整 core 测试共 7,977 个用例通过;
外部 1.2.83 兼容矩阵中仅消除了对应的 unwrapped map 失败。

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.

1 participant