fix: initialize writable unwrapped map fields - #7815
Open
DarrenChangJR wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 whoseinitial value is null therefore throws
NullPointerExceptioninFieldReaderMapReadOnly.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
UnwrappedTestcover:Map<String, Long>field;Integerrange to verify generic conversion;TreeMapconcrete type;Validation performed:
UnwrappedTest;mvn -pl core validate;coresuite: 7,977 tests, no failures or errors;removed and unrelated findings are unchanged.
Checklist
中文说明
修改内容和原因
反序列化未知字段到 unwrapped map 时,当前实现假设 map 已经初始化。因此,
当可写的
@JSONField(unwrapped = true)map 字段初始值为null时,FieldReaderMapReadOnly.processExtra会抛出NullPointerException。本修改在属性可写时,通过现有的强类型 map reader 创建声明的 map 类型,
先赋值到对象,再写入额外字段。这样可以保留具体 map 类型和泛型值转换;
只读 map 不会被赋值。
测试
UnwrappedTest新增覆盖:Map<String, Long>;Integer范围的数值验证泛型转换;TreeMap具体类型;聚焦测试和 Maven
validate通过,完整core测试共 7,977 个用例通过;外部 1.2.83 兼容矩阵中仅消除了对应的 unwrapped map 失败。