Repository navigation
Conversation
…mantics In v1, unmarshal methods are only called on a value of an unnamed type if the value is reached through a pointer (see indirect in decode.go), with the exception of UnmarshalText for map keys. An unnamed type only has methods through embedded fields, so v1 decodes the fields of, e.g., an anonymous struct embedding *T instead of calling the promoted (*T).UnmarshalJSON method, and allocates the embedded pointer. The v2 implementation used by encoding/json called the promoted method regardless, which panics with a nil pointer dereference when the embedded field is a nil pointer, and otherwise produces different results than v1 for anonymous struct fields, slice/array elements, and map values. Under CallMethodsWithLegacySemantics, skip unmarshal methods on values of unnamed types, except when the value is obtained by dereferencing a pointer (the top-level argument or a pointer element) or, for UnmarshalText, when used as a map key. Pure v2 semantics are unchanged. Fixes golang#81244
|
This PR (HEAD: e32fbc1) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/851565. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/851565. |
In v1, unmarshal methods are only called on a value of an unnamed type
if the value is reached through a pointer (see indirect in decode.go),
with the exception of UnmarshalText for map keys.
An unnamed type only has methods through embedded fields, so v1 decodes
the fields of, e.g., an anonymous struct embedding *T instead of calling
the promoted (*T).UnmarshalJSON method, and allocates the embedded pointer.
The v2 implementation used by encoding/json called the promoted method
regardless, which panics with a nil pointer dereference when the
embedded field is a nil pointer, and otherwise produces different
results than v1 for anonymous struct fields, slice/array elements,
and map values.
Under CallMethodsWithLegacySemantics, skip unmarshal methods on values
of unnamed types, except when the value is obtained by dereferencing
a pointer (the top-level argument or a pointer element) or, for
UnmarshalText, when used as a map key. Pure v2 semantics are unchanged.
Fixes #81244