diff options
Diffstat (limited to 'src/encoding/json/encode.go')
| -rw-r--r-- | src/encoding/json/encode.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 317a5a940d..66d1a183b0 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -1094,11 +1094,18 @@ func typeFields(t reflect.Type) []field { isUnexported := sf.PkgPath != "" if sf.Anonymous { t := sf.Type - if t.Kind() == reflect.Ptr { + isPointer := t.Kind() == reflect.Ptr + if isPointer { t = t.Elem() } - if isUnexported && t.Kind() != reflect.Struct { - // Ignore embedded fields of unexported non-struct types. + isStruct := t.Kind() == reflect.Struct + if isUnexported && (!isStruct || isPointer) { + // Ignore embedded fields of unexported non-struct types + // or pointers to unexported struct types. + // + // The latter is forbidden because unmarshal is unable + // to assign a new struct to the unexported field. + // See https://golang.org/issue/21357 continue } // Do not ignore embedded fields of unexported struct types |
