@@ -111,7 +111,7 @@ func makeMethodArshaler(fncs *arshaler, t reflect.Type) *arshaler {
111
111
(needAddr && va .forcedAddr ) {
112
112
return prevMarshal (enc , va , mo )
113
113
}
114
- marshaler := va . Addr (). Interface ().(encoding. TextMarshaler )
114
+ marshaler , _ := reflect. TypeAssert [encoding. TextMarshaler ]( va . Addr () )
115
115
if err := export .Encoder (enc ).AppendRaw ('"' , false , func (b []byte ) ([]byte , error ) {
116
116
b2 , err := marshaler .MarshalText ()
117
117
return append (b , b2 ... ), err
@@ -137,7 +137,7 @@ func makeMethodArshaler(fncs *arshaler, t reflect.Type) *arshaler {
137
137
(needAddr && va .forcedAddr ) {
138
138
return prevMarshal (enc , va , mo )
139
139
}
140
- appender := va . Addr (). Interface ().(encoding. TextAppender )
140
+ appender , _ := reflect. TypeAssert [encoding. TextAppender ]( va . Addr () )
141
141
if err := export .Encoder (enc ).AppendRaw ('"' , false , appender .AppendText ); err != nil {
142
142
err = wrapSkipFunc (err , "append method" )
143
143
if mo .Flags .Get (jsonflags .ReportErrorsWithLegacySemantics ) {
@@ -160,7 +160,7 @@ func makeMethodArshaler(fncs *arshaler, t reflect.Type) *arshaler {
160
160
((needAddr && va .forcedAddr ) || export .Encoder (enc ).Tokens .Last .NeedObjectName ()) {
161
161
return prevMarshal (enc , va , mo )
162
162
}
163
- marshaler := va .Addr (). Interface ().( Marshaler )
163
+ marshaler , _ := reflect. TypeAssert [ Marshaler ]( va .Addr ())
164
164
val , err := marshaler .MarshalJSON ()
165
165
if err != nil {
166
166
err = wrapSkipFunc (err , "marshal method" )
@@ -194,7 +194,8 @@ func makeMethodArshaler(fncs *arshaler, t reflect.Type) *arshaler {
194
194
xe := export .Encoder (enc )
195
195
prevDepth , prevLength := xe .Tokens .DepthLength ()
196
196
xe .Flags .Set (jsonflags .WithinArshalCall | 1 )
197
- err := va .Addr ().Interface ().(MarshalerTo ).MarshalJSONTo (enc )
197
+ marshaler , _ := reflect.TypeAssert [MarshalerTo ](va .Addr ())
198
+ err := marshaler .MarshalJSONTo (enc )
198
199
xe .Flags .Set (jsonflags .WithinArshalCall | 0 )
199
200
currDepth , currLength := xe .Tokens .DepthLength ()
200
201
if (prevDepth != currDepth || prevLength + 1 != currLength ) && err == nil {
@@ -233,7 +234,7 @@ func makeMethodArshaler(fncs *arshaler, t reflect.Type) *arshaler {
233
234
return newUnmarshalErrorAfter (dec , t , errNonStringValue )
234
235
}
235
236
s := jsonwire .UnquoteMayCopy (val , flags .IsVerbatim ())
236
- unmarshaler := va . Addr (). Interface ().(encoding. TextUnmarshaler )
237
+ unmarshaler , _ := reflect. TypeAssert [encoding. TextUnmarshaler ]( va . Addr () )
237
238
if err := unmarshaler .UnmarshalText (s ); err != nil {
238
239
err = wrapSkipFunc (err , "unmarshal method" )
239
240
if uo .Flags .Get (jsonflags .ReportErrorsWithLegacySemantics ) {
@@ -260,7 +261,7 @@ func makeMethodArshaler(fncs *arshaler, t reflect.Type) *arshaler {
260
261
if err != nil {
261
262
return err // must be a syntactic or I/O error
262
263
}
263
- unmarshaler := va .Addr (). Interface ().( Unmarshaler )
264
+ unmarshaler , _ := reflect. TypeAssert [ Unmarshaler ]( va .Addr ())
264
265
if err := unmarshaler .UnmarshalJSON (val ); err != nil {
265
266
err = wrapSkipFunc (err , "unmarshal method" )
266
267
if uo .Flags .Get (jsonflags .ReportErrorsWithLegacySemantics ) {
@@ -284,7 +285,8 @@ func makeMethodArshaler(fncs *arshaler, t reflect.Type) *arshaler {
284
285
xd := export .Decoder (dec )
285
286
prevDepth , prevLength := xd .Tokens .DepthLength ()
286
287
xd .Flags .Set (jsonflags .WithinArshalCall | 1 )
287
- err := va .Addr ().Interface ().(UnmarshalerFrom ).UnmarshalJSONFrom (dec )
288
+ unmarshaler , _ := reflect.TypeAssert [UnmarshalerFrom ](va .Addr ())
289
+ err := unmarshaler .UnmarshalJSONFrom (dec )
288
290
xd .Flags .Set (jsonflags .WithinArshalCall | 0 )
289
291
currDepth , currLength := xd .Tokens .DepthLength ()
290
292
if (prevDepth != currDepth || prevLength + 1 != currLength ) && err == nil {
0 commit comments