fix OpStructFieldOmitEmptyMarshalJSON with custom type marshaller on all VMs

This commit is contained in:
IncSW 2021-04-12 11:41:31 +03:00
parent 42adc0a5ab
commit 53590387e6
No known key found for this signature in database
GPG Key ID: 89876FA64BFB2D57
4 changed files with 24 additions and 4 deletions

View File

@ -3646,8 +3646,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
code = code.NextField code = code.NextField
break break
} }
iface := ptrToInterface(code, p)
if code.Nilcheck && encoder.IsNilForMarshaler(iface) {
code = code.NextField
break
}
b = append(b, code.Key...) b = append(b, code.Key...)
bb, err := appendMarshalJSON(code, b, ptrToInterface(code, p), false) bb, err := appendMarshalJSON(code, b, iface, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3646,8 +3646,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
code = code.NextField code = code.NextField
break break
} }
iface := ptrToInterface(code, p)
if code.Nilcheck && encoder.IsNilForMarshaler(iface) {
code = code.NextField
break
}
b = append(b, code.EscapedKey...) b = append(b, code.EscapedKey...)
bb, err := appendMarshalJSON(code, b, ptrToInterface(code, p), true) bb, err := appendMarshalJSON(code, b, iface, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3901,10 +3901,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
code = code.NextField code = code.NextField
break break
} }
iface := ptrToInterface(code, p)
if code.Nilcheck && encoder.IsNilForMarshaler(iface) {
code = code.NextField
break
}
b = appendIndent(ctx, b, code.Indent) b = appendIndent(ctx, b, code.Indent)
b = append(b, code.EscapedKey...) b = append(b, code.EscapedKey...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3901,10 +3901,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
code = code.NextField code = code.NextField
break break
} }
iface := ptrToInterface(code, p)
if code.Nilcheck && encoder.IsNilForMarshaler(iface) {
code = code.NextField
break
}
b = appendIndent(ctx, b, code.Indent) b = appendIndent(ctx, b, code.Indent)
b = append(b, code.Key...) b = append(b, code.Key...)
b = append(b, ' ') b = append(b, ' ')
bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }