Skip to content

Commit 9461257

Browse files
fixed null in number json tag string (#480)
1 parent 5bce16d commit 9461257

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLD
99
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
1010
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1111
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12+
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
1213
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1314
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
1415
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

reflect_struct_decoder.go

+5
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,11 @@ type stringModeNumberDecoder struct {
10751075
}
10761076

10771077
func (decoder *stringModeNumberDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
1078+
if iter.WhatIsNext() == NilValue {
1079+
decoder.elemDecoder.Decode(ptr, iter)
1080+
return
1081+
}
1082+
10781083
c := iter.nextToken()
10791084
if c != '"' {
10801085
iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c}))

value_tests/struct_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func init() {
2626
Field int `json:"field"`
2727
})(nil),
2828
input: `{"field": null}`,
29+
}, unmarshalCase{
30+
ptr: (*struct {
31+
Field int `json:"field,string"`
32+
})(nil),
33+
input: `{"field": null}`,
2934
}, unmarshalCase{
3035
ptr: (*struct {
3136
ID int `json:"id"`

0 commit comments

Comments
 (0)