Fix encoding of pointered MarshalJSON type with omitempty

This commit is contained in:
Masaaki Goshima 2021-01-22 18:26:28 +09:00
parent d59cdefc1d
commit fa4d5842e6
2 changed files with 4 additions and 4 deletions

View File

@ -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)

View File

@ -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)