forked from mirror/go-json
Keep reference value while encoding by MarshalJSON
This commit is contained in:
parent
d4b5171fdf
commit
d933310ad4
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
|
@ -278,6 +279,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
if err != nil {
|
||||
return nil, errMarshaler(code, err)
|
||||
}
|
||||
runtime.KeepAlive(v)
|
||||
if len(bb) == 0 {
|
||||
return nil, errUnexpectedEndOfJSON(
|
||||
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"unsafe"
|
||||
)
|
||||
|
@ -240,6 +241,7 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
if err != nil {
|
||||
return nil, errMarshaler(code, err)
|
||||
}
|
||||
runtime.KeepAlive(v)
|
||||
if len(bb) == 0 {
|
||||
return nil, errUnexpectedEndOfJSON(
|
||||
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"unsafe"
|
||||
)
|
||||
|
@ -253,6 +254,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
if err != nil {
|
||||
return nil, errMarshaler(code, err)
|
||||
}
|
||||
runtime.KeepAlive(v)
|
||||
if len(bb) == 0 {
|
||||
return nil, errUnexpectedEndOfJSON(
|
||||
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"unsafe"
|
||||
)
|
||||
|
@ -253,6 +254,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
if err != nil {
|
||||
return nil, errMarshaler(code, err)
|
||||
}
|
||||
runtime.KeepAlive(v)
|
||||
if len(bb) == 0 {
|
||||
return nil, errUnexpectedEndOfJSON(
|
||||
fmt.Sprintf("error calling MarshalJSON for type %s", code.typ),
|
||||
|
|
Loading…
Reference in New Issue