fix(util/gconv): fix nested map conversion data loss in MapToMap#4612
Merged
hailaz merged 2 commits intogogf:masterfrom Jan 15, 2026
Merged
fix(util/gconv): fix nested map conversion data loss in MapToMap#4612hailaz merged 2 commits intogogf:masterfrom
hailaz merged 2 commits intogogf:masterfrom
Conversation
When converting nested maps like map[string]map[string]float64, the data was lost because MapToMap incorrectly called Struct() for map value types. This fix separates the handling of reflect.Map from reflect.Struct, using recursive MapToMap calls for nested maps. Closes gogf#4542
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a data loss bug in nested map conversions when using gconv.Scan() or MapToMap(). The issue occurred when converting map[string]any to map[string]map[string]float64, where nested map data was incorrectly handled by calling Struct() instead of recursively calling MapToMap().
Changes:
- Separated
reflect.Maphandling fromreflect.Structin the type switch - Added recursive
MapToMap()call for nested map types - Added comprehensive test coverage for nested maps, deep nesting, edge cases, and regression testing
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| util/gconv/internal/converter/converter_maptomap.go | Split the combined case reflect.Map, reflect.Struct: into separate cases, with reflect.Map now recursively calling MapToMap() |
| util/gconv/gconv_z_unit_issue_test.go | Added Test_Issue4542 with 7 test cases covering nested maps, deep nesting, different key types, empty maps, struct regression, and recursion safety |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
hailaz
approved these changes
Jan 15, 2026
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.
Summary
gconv.Scan()orMapToMap()map[string]anytomap[string]map[string]float64, the nested data was lostMapToMapincorrectly calledStruct()for map value typesreflect.Maphandling fromreflect.Struct, use recursiveMapToMap()for nested mapsTest plan
Closes #4542