Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit 2017f38

Browse files
committed
fix encoding of nil marshaler interface
1 parent ddc5af4 commit 2017f38

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

feature_reflect_native.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,11 @@ func (encoder *marshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
662662
templateInterface := encoder.templateInterface
663663
templateInterface.word = ptr
664664
realInterface := (*interface{})(unsafe.Pointer(&templateInterface))
665-
marshaler := (*realInterface).(json.Marshaler)
665+
marshaler, ok := (*realInterface).(json.Marshaler)
666+
if !ok {
667+
stream.WriteVal(nil)
668+
return
669+
}
666670

667671
bytes, err := marshaler.MarshalJSON()
668672
if err != nil {

0 commit comments

Comments
 (0)