fix: NameFilter returning null causes Map keys to serialize as null (#7644)#7658
Open
1919chichi wants to merge 1 commit into
Open
fix: NameFilter returning null causes Map keys to serialize as null (#7644)#76581919chichi wants to merge 1 commit into
1919chichi wants to merge 1 commit into
Conversation
…libaba#7644) When NameFilter.process() returns null for a Map entry key in ObjectWriterImplMap, the key was overwritten with null and serialized as `null:value` instead of preserving the original key. Add a null guard so that a null return value falls back to the original key, consistent with the behavior in ObjectWriterAdapter (POJO fields) and JSONObject.nameFilter(). Fixes alibaba#7644
wenshao
approved these changes
Jun 22, 2026
wenshao
left a comment
Member
There was a problem hiding this comment.
Fix is correct and minimal. The null guard in ObjectWriterImplMap.writeWithFilter() properly preserves the original Map key when NameFilter.process() returns null, consistent with the existing behavior in JSONObject.nameFilter(). Tests cover the core scenarios well. LGTM! ✅
— qwen3.7-max via Qwen Code /review
wenshao
approved these changes
Jul 15, 2026
wenshao
left a comment
Member
There was a problem hiding this comment.
No issues found. LGTM! ✅
— Qwen Code via Qwen Code /review
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 / why we need it?
When
NameFilter.process()returnsnullfor a Map entry key inObjectWriterImplMap.writeWithFilter(), the key is directly overwritten withnulland serialized asnull:"value"instead of preserving the original key name.Fixes #7644
Summary of your change
Added a null guard in
ObjectWriterImplMap.writeWithFilter()so that whenNameFilter.process()returnsnull, the original key is preserved — consistent with the existing behavior in:ObjectWriterAdapter(POJO fields):boolean nameChanged = filteredName != null && ...JSONObject.nameFilter():if (processName != null && !processName.equals(key))Before:
After:
Please indicate you've done the following: