mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
This commit is contained in:
parent
ba1deb1cee
commit
15f232456a
1 changed files with 0 additions and 3 deletions
|
|
@ -113,9 +113,6 @@ func Unmarshal(data []byte, v any) error {
|
||||||
// The input can be assumed to be a valid encoding of
|
// The input can be assumed to be a valid encoding of
|
||||||
// a JSON value. UnmarshalJSON must copy the JSON data
|
// a JSON value. UnmarshalJSON must copy the JSON data
|
||||||
// if it wishes to retain the data after returning.
|
// 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 {
|
type Unmarshaler interface {
|
||||||
UnmarshalJSON([]byte) error
|
UnmarshalJSON([]byte) error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue