fix: using rv directly (#1213)

pull/1231/head
Yongzheng Lai 3 years ago committed by GitHub
parent b6d005b21e
commit 97222012e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      encoding/json/json.go

@ -39,7 +39,7 @@ func (codec) Marshal(v interface{}) ([]byte, error) {
func (codec) Unmarshal(data []byte, v interface{}) error { func (codec) Unmarshal(data []byte, v interface{}) error {
rv := reflect.ValueOf(v) rv := reflect.ValueOf(v)
for rv.Kind() == reflect.Ptr { for rv := rv; rv.Kind() == reflect.Ptr; {
if rv.IsNil() { if rv.IsNil() {
rv.Set(reflect.New(rv.Type().Elem())) rv.Set(reflect.New(rv.Type().Elem()))
} }
@ -47,7 +47,7 @@ func (codec) Unmarshal(data []byte, v interface{}) error {
} }
if m, ok := v.(proto.Message); ok { if m, ok := v.(proto.Message); ok {
return UnmarshalOptions.Unmarshal(data, m) return UnmarshalOptions.Unmarshal(data, m)
} else if m, ok := reflect.Indirect(reflect.ValueOf(v)).Interface().(proto.Message); ok { } else if m, ok := reflect.Indirect(rv).Interface().(proto.Message); ok {
return UnmarshalOptions.Unmarshal(data, m) return UnmarshalOptions.Unmarshal(data, m)
} }
return json.Unmarshal(data, v) return json.Unmarshal(data, v)

Loading…
Cancel
Save