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