Reviewers: golang-dev_googlegroups.com,
Message:
Hello [email protected],
I'd like you to review this change to
https://code.google.com/p/go
Description:
json: when decoding to a nil interface, make sure the dest can be
assigned to interface{}
All tests pass. To add a test case for this issue, I'd like to know what
to do if it can't be unmarshaled:
1. Ignore, and continue (current implementation)
2. return error
Fixes issue 4222.
Please review this at https://codereview.appspot.com/7102053/
Affected files:
M src/pkg/encoding/json/decode.go
Index: src/pkg/encoding/json/decode.go
===================================================================
--- a/src/pkg/encoding/json/decode.go
+++ b/src/pkg/encoding/json/decode.go
@@ -442,7 +442,9 @@
// Decoding into nil interface? Switch to non-reflect code.
if v.Kind() == reflect.Interface {
- v.Set(reflect.ValueOf(d.objectInterface()))
+ if v.Type().NumMethod() == 0 {
+ v.Set(reflect.ValueOf(d.objectInterface()))
+ }
return
}