encoding/json: UnmarshalTypeError is clobbered when using nested custom marshallers #61337
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Summary
(*encoding.json.decodeState).addErrorContext
sets UnmarshalTypeError's Field value based on the decode state's error context. However when a custom UnmarshalJSON implementation callsjson.Unmarshal
, this creates a new nested decode state with its own error context. When the nested unmarshal call returns an error, and that error is seen by the original decode state, the original decode state's error context's field stack is empty. Thus when the original decode state sets the error's Field value, it clobbers the field name from the nested call.What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/Z1X4MEFdocS
What did you expect to see?
json: cannot unmarshal number into Go struct field BetaWrapper.beta.field of type string
What did you see instead?
json: cannot unmarshal number into Go struct field AlphaWrapper.beta of type string
The text was updated successfully, but these errors were encountered: