mirror of https://github.com/goccy/go-json.git
Merge pull request #375 from orisano/fix/#339
fix: wrong the detection method of nilable
This commit is contained in:
commit
6726210c9c
|
@ -9,6 +9,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
@ -2388,3 +2389,20 @@ func TestIssue324(t *testing.T) {
|
|||
t.Fatalf("failed to encode. expected %q but got %q", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue339(t *testing.T) {
|
||||
type T1 struct {
|
||||
*big.Int
|
||||
}
|
||||
type T2 struct {
|
||||
T1 T1 `json:"T1"`
|
||||
}
|
||||
v := T2{T1{Int: big.NewInt(10000)}}
|
||||
b, err := json.Marshal(&v)
|
||||
assertErr(t, err)
|
||||
got := string(b)
|
||||
expected := `{"T1":10000}`
|
||||
if got != expected {
|
||||
t.Errorf("unexpected result: %v != %v", got, expected)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -853,6 +853,9 @@ func (c *Compiler) implementsMarshalText(typ *runtime.Type) bool {
|
|||
}
|
||||
|
||||
func (c *Compiler) isNilableType(typ *runtime.Type) bool {
|
||||
if !runtime.IfaceIndir(typ) {
|
||||
return true
|
||||
}
|
||||
switch typ.Kind() {
|
||||
case reflect.Ptr:
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue