diff options
| author | Joe Tsai <joetsai@digital-static.net> | 2017-12-05 22:38:36 -0800 |
|---|---|---|
| committer | Joe Tsai <thebrokentoaster@gmail.com> | 2017-12-06 19:27:26 +0000 |
| commit | 70f441bc49afa4e9d10c27d7ed5733c4df7bddd3 (patch) | |
| tree | ae5363b4d2af271315713978c3e7551c9240e923 /src/encoding/json/encode_test.go | |
| parent | 0e76143ef1208db7eeb06e939401666065d41337 (diff) | |
| download | go-70f441bc49afa4e9d10c27d7ed5733c4df7bddd3.tar.xz | |
encoding/json: error when trying to set an embedded pointer to unexported struct types
This CL reverts CL 76851 and takes a different approach to #21357.
The changes in encode.go and encode_test.go are reverts that
rolls back the changed behavior in CL 76851 where
embedded pointers to unexported struct types were
unilaterally ignored in both marshal and unmarshal.
Instead, these fields are handled as before with the exception that
it returns an error when Unmarshal is unable to set an unexported field.
The behavior of Marshal is now unchanged with regards to #21357.
This policy maintains the greatest degree of backwards compatibility
and avoids silently discarding data the user may have expected to be present.
Fixes #21357
Change-Id: I7dc753280c99f786ac51acf7e6c0246618c8b2b1
Reviewed-on: https://go-review.googlesource.com/82135
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/encoding/json/encode_test.go')
| -rw-r--r-- | src/encoding/json/encode_test.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/encoding/json/encode_test.go b/src/encoding/json/encode_test.go index df7338c98d..0f194e13d2 100644 --- a/src/encoding/json/encode_test.go +++ b/src/encoding/json/encode_test.go @@ -364,9 +364,8 @@ func TestAnonymousFields(t *testing.T) { want: `{"X":2,"Y":4}`, }, { // Exported fields of pointers to embedded structs should have their - // exported fields be serialized only for exported struct types. - // Pointers to unexported structs are not allowed since the decoder - // is unable to allocate a struct for that field + // exported fields be serialized regardless of whether the struct types + // themselves are exported. label: "EmbeddedStructPointer", makeInput: func() interface{} { type ( @@ -379,7 +378,7 @@ func TestAnonymousFields(t *testing.T) { ) return S{&s1{1, 2}, &S2{3, 4}} }, - want: `{"Y":4}`, + want: `{"X":2,"Y":4}`, }, { // Exported fields on embedded unexported structs at multiple levels // of nesting should still be serialized. |
