mirror of https://github.com/goccy/go-json.git
Fix operation of StructFieldOmitEmptyMarshalJSON
This commit is contained in:
parent
ea71048fce
commit
20b409ed1f
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue