Fix operation of StructFieldOmitEmptyMarshalJSON

This commit is contained in:
Masaaki Goshima 2021-01-22 20:08:57 +09:00
parent ea71048fce
commit 20b409ed1f
2 changed files with 8 additions and 2 deletions

View File

@ -7870,8 +7870,11 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
case opStructFieldOmitEmptyMarshalJSON: case opStructFieldOmitEmptyMarshalJSON:
ptr := load(ctxptr, code.headIdx) ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset p := ptr + code.offset
if code.typ.Kind() == reflect.Ptr && code.typ.Elem().Implements(marshalJSONType) {
p = e.ptrToPtr(p)
}
v := e.ptrToInterface(code, p) v := e.ptrToInterface(code, p)
if v != nil && (code.typ.Kind() != reflect.Ptr || e.ptrToPtr(p) != 0) { if v != nil && p != 0 {
bb, err := v.(Marshaler).MarshalJSON() bb, err := v.(Marshaler).MarshalJSON()
if err != nil { if err != nil {
return nil, errMarshaler(code, err) return nil, errMarshaler(code, err)

View File

@ -7840,8 +7840,11 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
case opStructFieldOmitEmptyMarshalJSON: case opStructFieldOmitEmptyMarshalJSON:
ptr := load(ctxptr, code.headIdx) ptr := load(ctxptr, code.headIdx)
p := ptr + code.offset p := ptr + code.offset
if code.typ.Kind() == reflect.Ptr && code.typ.Elem().Implements(marshalJSONType) {
p = e.ptrToPtr(p)
}
v := e.ptrToInterface(code, p) v := e.ptrToInterface(code, p)
if v != nil && (code.typ.Kind() != reflect.Ptr || e.ptrToPtr(p) != 0) { if v != nil && p != 0 {
bb, err := v.(Marshaler).MarshalJSON() bb, err := v.(Marshaler).MarshalJSON()
if err != nil { if err != nil {
return nil, errMarshaler(code, err) return nil, errMarshaler(code, err)