Repository navigation
fix(mapping): support unmarshaling into interface{} fields for mixed types (fix #5721) - #5749
Jaymr1031-Z wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates go-zero’s core/mapping JSON unmarshaling logic to correctly populate interface{} / any struct fields when the incoming JSON contains mixed primitive types (notably json.Number vs string/bool), aligning behavior with standard encoding/json decoding and fixing the reported type mismatch for field ... failure in httpx.Parse/mapping.UnmarshalJsonBytes.
Changes:
- Allow primitive values (including
json.Number) to be assigned intointerface{}fields during unmarshaling. - Add a unit test that verifies mixed string/number values can be unmarshaled into
anyfields.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| switch v := mapValue.(type) { | ||
| case json.Number: | ||
| if typeKind == reflect.Interface { | ||
| return fillWithSameType(fieldType, value, mapValue, opts) | ||
| } |
ca96f7e to
73b70a6
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |

Fixes #5721
Problem
httpx.Parse (and mapping.UnmarshalJsonBytes) failed with ype mismatch for field "..." when unmarshaling into a struct field of type interface{} / �ny whose JSON value is a primitive string, number (json.Number), or bool. This occurred because processFieldPrimitive checked ypeKind == valueKind without handling
eflect.Interface.
Solution