You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
httpx.Parse fails to unmarshal interface{} field with mixed string/number values #5721
httpx.Parse fails to parse a request body that contains an interface{} field when the actual JSON value can be either a string or a number. The same request works perfectly with json.NewDecoder(r.Body).Decode(&req), indicating that the JSON is valid and the structure definition is correct.
To Reproduce
Define the following API types:
typeUpdateReqstruct {
Iduint64`json:"id"`Items []DataItem`json:"datas,optional"`
}
typeDataItemstruct {
Valueinterface{} `json:"value,omitempty"`// can be string or numberValueTypeint`json:"valueType"`// 0 for string, 1 for number
}
Hi, I would like to work on this issue. I reproduced the failure locally: UnmarshalJsonReader returns 'type mismatch for field "datas[0].value"' when an interface{} field receives mixed string/number JSON values.
Root cause: the mapping unmarshaler has no handling for empty-interface fields. In processFieldPrimitive, an interface{} field matches neither the same-kind branch nor the json.Number branch, so it always falls through to newTypeMismatchError.
I'm preparing a minimal fix so interface{} fields receive the raw decoded JSON value (strings stay strings, numbers stay json.Number because jsonx uses UseNumber), plus a regression test. I'll open a PR once the change is ready.
Activity
junnhwan commentedon Aug 11, 2026
Hi, I would like to work on this issue. I reproduced the failure locally: UnmarshalJsonReader returns 'type mismatch for field "datas[0].value"' when an interface{} field receives mixed string/number JSON values.
Root cause: the mapping unmarshaler has no handling for empty-interface fields. In processFieldPrimitive, an interface{} field matches neither the same-kind branch nor the json.Number branch, so it always falls through to newTypeMismatchError.
I'm preparing a minimal fix so interface{} fields receive the raw decoded JSON value (strings stay strings, numbers stay json.Number because jsonx uses UseNumber), plus a regression test. I'll open a PR once the change is ready.
fix(mapping): support unmarshaling into interface{} fields for mixed …