[go] encoding/json/v2: allow streaming JSON methods to return errors.ErrUnsupported

0 views
Skip to first unread message

Joseph Tsai (Gerrit)

unread,
Feb 13, 2026, 7:33:15 PMFeb 13
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Junyang Shao, Damien Neil, Johan Brandhorst-Satzkorn, Go LUCI, Daniel Martí, Michael Pratt, golang-co...@googlegroups.com

Joseph Tsai submitted the change

Change information

Commit message:
encoding/json/v2: allow streaming JSON methods to return errors.ErrUnsupported

Allow the MarshalJSONTo and UnmarshalJSONFrom methods
to return errors.ErrUnsupported to be skipped in a similar manner
to how the caller-specified functions can be skipped as well.

Note that the v1 MarshalJSON and UnmarshalJSON methods may not
return errors.ErrUnsupported as that would be a breaking change.
Also, we couldn't implement it for UnmarshalJSON since
that requires consuming the value, which changes the state of
the underlying jsontext.Decoder.

A side-effect of this change is that MarshalJSONTo and UnmarshalJSONFrom
methods may now return sentinel errors. We document that users
should avoid calling this methods directly and instead
rely on MarshalEncode and UnmarshalDecode,
which can handle the ErrUnsupported sentinel error and
others that we may add in the future.

Fixes #74324
Fixes #76712
Change-Id: I851e907ef8d25e31964148515879a243cb5069c5
Reviewed-by: Damien Neil <dn...@google.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.br...@gmail.com>
Reviewed-by: Junyang Shao <shaoj...@google.com>
Files:
  • M src/encoding/json/v2/arshal.go
  • M src/encoding/json/v2/arshal_methods.go
  • M src/encoding/json/v2/arshal_test.go
Change size: M
Delta: 3 files changed, 55 insertions(+), 13 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Junyang Shao, +2 by Damien Neil, +2 by Johan Brandhorst-Satzkorn
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I851e907ef8d25e31964148515879a243cb5069c5
Gerrit-Change-Number: 744941
Gerrit-PatchSet: 2
Gerrit-Owner: Joseph Tsai <joe...@digital-static.net>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Daniel Martí <mv...@mvdan.cc>
Gerrit-Reviewer: Johan Brandhorst-Satzkorn <johan.br...@gmail.com>
Gerrit-Reviewer: Joseph Tsai <joe...@digital-static.net>
Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages