Selaa lähdekoodia

fix encoding of nil marshaler interface

Jason Toffaletti 8 vuotta sitten
vanhempi
commit
2017f3866b
1 muutettua tiedostoa jossa 5 lisäystä ja 1 poistoa
  1. 5 1
      feature_reflect_native.go

+ 5 - 1
feature_reflect_native.go

@@ -662,7 +662,11 @@ func (encoder *marshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
 	templateInterface := encoder.templateInterface
 	templateInterface.word = ptr
 	realInterface := (*interface{})(unsafe.Pointer(&templateInterface))
-	marshaler := (*realInterface).(json.Marshaler)
+	marshaler, ok := (*realInterface).(json.Marshaler)
+	if !ok {
+		stream.WriteVal(nil)
+		return
+	}
 
 	bytes, err := marshaler.MarshalJSON()
 	if err != nil {