From: Joe Tsai Date: Sat, 28 Dec 2024 01:24:30 +0000 (-0800) Subject: encoding/json: remove suggestion on Unmarshaler with JSON null X-Git-Tag: go1.24rc2~6^2~42 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=15f232456a;p=gostls13.git encoding/json: remove suggestion on Unmarshaler with JSON null It is not true that Unmarshal always treats a JSON null as being equivalent to a no-op. For bools, ints, uints, floats, strings, arrays, and structs, it treats a JSON null as a no-op. However, for []byte, slice, map, pointer, or interface, it zeros the underlying value. Remove this suggestion as the actual behavior is inconsistent. Note that the proposed behavior in v2 Unmarshal is to consistently zero out the underlying value. Change-Id: I02cef0bf7919f25cfd0aceb04486d37498761181 Reviewed-on: https://go-review.googlesource.com/c/go/+/638416 Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Run-TryBot: Joseph Tsai --- diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index 98102291ab..3b398c9fc3 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -113,9 +113,6 @@ func Unmarshal(data []byte, v any) error { // The input can be assumed to be a valid encoding of // a JSON value. UnmarshalJSON must copy the JSON data // if it wishes to retain the data after returning. -// -// By convention, to approximate the behavior of [Unmarshal] itself, -// Unmarshalers implement UnmarshalJSON([]byte("null")) as a no-op. type Unmarshaler interface { UnmarshalJSON([]byte) error }