diff options
| author | Joe Tsai <joetsai@digital-static.net> | 2025-06-21 21:01:32 -0700 |
|---|---|---|
| committer | Joseph Tsai <joetsai@digital-static.net> | 2025-09-09 17:22:28 -0700 |
| commit | e6605a1bcc56523c0168caf765399dede7d3d1e4 (patch) | |
| tree | e0d0e0b917a017db6692dbabe5f3a67eff2a0689 /src/encoding/json/encode.go | |
| parent | 4c20f7f15a9a8eed50d8cbb8be8f74d449093a5c (diff) | |
| download | go-e6605a1bcc56523c0168caf765399dede7d3d1e4.tar.xz | |
encoding/json: use reflect.TypeAssert
Updates #62121
Change-Id: Ic3c4fe84a5dacfd8270aba0d5dd59f83f0a9030f
Reviewed-on: https://go-review.googlesource.com/c/go/+/701955
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/encoding/json/encode.go')
| -rw-r--r-- | src/encoding/json/encode.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 29fcc91fd7..1b7942dd3a 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -475,7 +475,7 @@ func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { e.WriteString("null") return } - m, ok := v.Interface().(Marshaler) + m, ok := reflect.TypeAssert[Marshaler](v) if !ok { e.WriteString("null") return @@ -498,7 +498,7 @@ func addrMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { e.WriteString("null") return } - m := va.Interface().(Marshaler) + m, _ := reflect.TypeAssert[Marshaler](va) b, err := m.MarshalJSON() if err == nil { e.Grow(len(b)) @@ -516,7 +516,7 @@ func textMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { e.WriteString("null") return } - m, ok := v.Interface().(encoding.TextMarshaler) + m, ok := reflect.TypeAssert[encoding.TextMarshaler](v) if !ok { e.WriteString("null") return @@ -534,7 +534,7 @@ func addrTextMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { e.WriteString("null") return } - m := va.Interface().(encoding.TextMarshaler) + m, _ := reflect.TypeAssert[encoding.TextMarshaler](va) b, err := m.MarshalText() if err != nil { e.error(&MarshalerError{v.Type(), err, "MarshalText"}) @@ -991,7 +991,7 @@ func resolveKeyName(k reflect.Value) (string, error) { if k.Kind() == reflect.String { return k.String(), nil } - if tm, ok := k.Interface().(encoding.TextMarshaler); ok { + if tm, ok := reflect.TypeAssert[encoding.TextMarshaler](k); ok { if k.Kind() == reflect.Pointer && k.IsNil() { return "", nil } |
