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>
This commit is contained in:
Joe Tsai 2025-06-21 21:01:32 -07:00 committed by Joseph Tsai
parent 4c20f7f15a
commit e6605a1bcc
6 changed files with 30 additions and 27 deletions

View file

@ -482,11 +482,11 @@ func indirect(v reflect.Value, decodingNull bool) (Unmarshaler, encoding.TextUnm
v.Set(reflect.New(v.Type().Elem()))
}
if v.Type().NumMethod() > 0 && v.CanInterface() {
if u, ok := v.Interface().(Unmarshaler); ok {
if u, ok := reflect.TypeAssert[Unmarshaler](v); ok {
return u, nil, reflect.Value{}
}
if !decodingNull {
if u, ok := v.Interface().(encoding.TextUnmarshaler); ok {
if u, ok := reflect.TypeAssert[encoding.TextUnmarshaler](v); ok {
return nil, u, reflect.Value{}
}
}