mirror of
https://github.com/golang/go.git
synced 2026-06-28 03:40:37 +00:00
encoding/json: clarify that v1 Unmarshal calls UnmarshalerFrom methods
This is the equivalent of CL 775180 for Unmarshal. Also, since the jsonv2 package is imported with a specific name, the hot-link can reference the local package name directly, instead of relying on a full-qualified package import path. Change-Id: I1223eeaac2d2aed53cfc681b5582e697813f2a36 Reviewed-on: https://go-review.googlesource.com/c/go/+/780107 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
c700213f6c
commit
f571fc93b0
2 changed files with 17 additions and 7 deletions
|
|
@ -35,12 +35,22 @@ import (
|
|||
// the value pointed at by the pointer. If the pointer is nil, Unmarshal
|
||||
// allocates a new value for it to point to.
|
||||
//
|
||||
// To unmarshal JSON into a value implementing [Unmarshaler],
|
||||
// Unmarshal calls that value's [Unmarshaler.UnmarshalJSON] method, including
|
||||
// when the input is a JSON null.
|
||||
// Otherwise, if the value implements [encoding.TextUnmarshaler]
|
||||
// and the input is a JSON quoted string, Unmarshal calls
|
||||
// [encoding.TextUnmarshaler.UnmarshalText] with the unquoted form of the string.
|
||||
// The JSON input is decoded according the following rules:
|
||||
//
|
||||
// - If the value type implements [jsonv2.UnmarshalerFrom],
|
||||
// then the UnmarshalJSONFrom method is called to decode the JSON value.
|
||||
// If the method returns [errors.ErrUnsupported],
|
||||
// then the input is decoded according to subsequent rules.
|
||||
//
|
||||
// - If the value type implements [Unmarshaler],
|
||||
// then the UnmarshalJSON method is called to decode the JSON value,
|
||||
// including when the input is a JSON null.
|
||||
//
|
||||
// - If the value implements [encoding.TextUnmarshaler] and
|
||||
// the input is a JSON string, then the UnmarshalText method
|
||||
// is called with the unquoted form of the string.
|
||||
//
|
||||
// Otherwise, Unmarshal uses the following type-dependent default decodings:
|
||||
//
|
||||
// To unmarshal JSON into a struct, Unmarshal matches incoming object
|
||||
// keys to the keys used by [Marshal] (either the struct field name or its tag),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import (
|
|||
//
|
||||
// The input value is encoded as JSON according the following rules:
|
||||
//
|
||||
// - If the value type implements [encoding/json/v2.MarshalerTo],
|
||||
// - If the value type implements [jsonv2.MarshalerTo],
|
||||
// then the MarshalJSONTo method is called to encode the value.
|
||||
// If the method returns [errors.ErrUnsupported],
|
||||
// then the input is encoded according to subsequent rules.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue