diff --git a/encode_vm.go b/encode_vm.go index 58c2c95..694ff17 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -7871,7 +7871,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte ptr := load(ctxptr, code.headIdx) p := ptr + code.offset v := e.ptrToInterface(code, p) - if v != nil { + if v != nil && (code.typ.Kind() != reflect.Ptr || e.ptrToPtr(p) != 0) { bb, err := v.(Marshaler).MarshalJSON() if err != nil { return nil, errMarshaler(code, err) @@ -9060,7 +9060,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte ptr := load(ctxptr, code.headIdx) p := ptr + code.offset v := e.ptrToInterface(code, p) - if v != nil { + if v != nil && (code.typ.Kind() != reflect.Ptr || e.ptrToPtr(p) != 0) { bb, err := v.(Marshaler).MarshalJSON() if err != nil { return nil, errMarshaler(code, err) diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index bef089c..839da2c 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -7841,7 +7841,7 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) ptr := load(ctxptr, code.headIdx) p := ptr + code.offset v := e.ptrToInterface(code, p) - if v != nil { + if v != nil && (code.typ.Kind() != reflect.Ptr || e.ptrToPtr(p) != 0) { bb, err := v.(Marshaler).MarshalJSON() if err != nil { return nil, errMarshaler(code, err) @@ -9046,7 +9046,7 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) ptr := load(ctxptr, code.headIdx) p := ptr + code.offset v := e.ptrToInterface(code, p) - if v != nil { + if v != nil && (code.typ.Kind() != reflect.Ptr || e.ptrToPtr(p) != 0) { bb, err := v.(Marshaler).MarshalJSON() if err != nil { return nil, errMarshaler(code, err)