encoding/json/v2: WithinArshalCall check does not work for nested calls · Issue #80116 · golang/go · GitHub
Skip to content 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 encoding/json/v2: WithinArshalCall check does not work for nested calls #80116 New issue Copy link New issue Copy link Open #82827 Open encoding/json/v2: WithinArshalCall check does not work for nested calls #80116 #82827 Copy link Labels NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Milestone Go1.28 Description dsnet opened on Jun 23, 2026 Issue body actions There's an internal WithinArshalCall flag that the "json" implementation sets whenever calling a user-provided marshaler or unmarshaler. The purpose of this flag is as a sanity check that causes Encoder.Reset and Decoder.Reset to panic. This check doesn't work for nested marshaler calls since inner call will clear the flag.
We should either drop the check (since it's only as a sanity protection) or fix it such that it only clears the flag if it was able to set it in the first place. Thus instead of: https://github.com/go-json-experiment/json/blob/60a0516c28953eb838073b7951a726fa12003537/arshal_methods.go#L195-L197 It'd be something like: if ! xe . Flags . Get ( jsonflags . WithinArshalCall ) { xe . Flags . Set ( jsonflags . WithinArshalCall | 1 ) defer func () { xe .
Flags . Set ( jsonflags . WithinArshalCall | 0 ) } } err := va . Addr (). Interface ().( MarshalerTo ). MarshalJSONTo ( enc , mo ) Overall, this is a pretty minor bug. Activity dsnet added this to json/v2 working group on Jun 23, 2026 github-project-automation moved this to Needs triage in json/v2 working group on Jun 23, 2026 dsnet moved this from Needs triage to Post-proposal in json/v2 working group on Jun 23, 2026 cagedmantis added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. on Jun 24, 2026 cagedmantis added this to the Go1.27 milestone on Jun 24, 2026 dsnet modified the milestones: Go1.27 , Go1.28 on Jul 1, 2026 erfansahebi commented on Oct 22, 2026 erfansahebi on Oct 22, 2026 · Hidden as low-quality show comment More actions github-project-automation moved this from Post-proposal to Needs triage in json/v2 working group on Nov 3, 2026 gopherbot commented on Nov 3, 2026 gopherbot on Nov 3, 2026 Contributor More actions Change https://go.dev/cl/858084 mentions this issue: encoding/json: fix nested marshal/unmarshal WithinArshalCall Sign up for free to join this conversation on GitHub.
Already have an account? Sign in to comment Metadata Metadata Assignees No one assigned Labels NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Type No type Projects json/v2 working group Status Needs triage Show more project fields Milestone Go1.28 No due date Relationships None yet Development No branches or pull requests Issue actions You can’t perform that action at this time.