aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/encode.go
diff options
context:
space:
mode:
authorthoeni <thoeni@gmail.com>2016-12-01 21:57:39 +0000
committerRuss Cox <rsc@golang.org>2017-06-14 19:01:08 +0000
commit296b35382c82081d6c90dcec570e6491a2b2598a (patch)
treea86a782db8baddc86c55f001fb6dcbbc9cbd9ae4 /src/encoding/json/encode.go
parente2160cc5713e4954b67ec4eabdb893d2880e10a0 (diff)
downloadgo-296b35382c82081d6c90dcec570e6491a2b2598a.tar.xz
encoding/json: don't marshal unexported embedded fields of non struct type
Marshal must process unexported embedded fields of struct type, looking for exported fields in those structs. However, it must not process unexported embedded fields of non-struct type. For example, consider: type t1 struct { X int } type t2 int type T struct { t1 t2 } When considering T, Marshal must process t1 to find t1.X. Marshal must not process t2, but it was. Fix that. Fixes #18009 Change-Id: I62ba0b65ba30fd927990e101a26405a9998787a3 Reviewed-on: https://go-review.googlesource.com/33773 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/encoding/json/encode.go')
-rw-r--r--src/encoding/json/encode.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go
index 4a5ab9c016..6fcea4735f 100644
--- a/src/encoding/json/encode.go
+++ b/src/encoding/json/encode.go
@@ -1093,7 +1093,7 @@ func typeFields(t reflect.Type) []field {
// Scan f.typ for fields to include.
for i := 0; i < f.typ.NumField(); i++ {
sf := f.typ.Field(i)
- if sf.PkgPath != "" && !sf.Anonymous { // unexported
+ if sf.PkgPath != "" && (!sf.Anonymous || sf.Type.Kind() != reflect.Struct) { // unexported
continue
}
tag := sf.Tag.Get("json")