Fix directLeader empty array serialization for WeChat Work user update API #3652
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.
Problem
When updating WeChat Work (企业微信) users, the
directLeader
field has specific API behavior:null
value: Field is ignored (no change to user's direct leaders)[]
: Resets direct leaders (clears all direct leaders)However, the current JSON serialization omits empty arrays entirely, preventing the API from resetting user direct leaders.
Root Cause
The
WxCpUserGsonAdapter.addArrayProperty()
method only includes arrays in JSON ifarray != null && array.length > 0
. This causes emptydirectLeader
arrays to be completely omitted from the serialized JSON.Solution
Modified the serialization logic for the
directLeader
field to include empty arrays:Before:
After:
Behavior Changes
new String[]{}
{}
(no field){"direct_leader":[]}
null
{}
(no field){}
(no field)new String[]{"a","b"}
{"direct_leader":["a","b"]}
{"direct_leader":["a","b"]}
Testing
Added comprehensive test coverage in
WxCpUserGsonAdapterTest.testDirectLeaderEmptyArraySerialization()
that verifies all three scenarios produce the correct JSON output.Fixes #3628.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.