Skip to content

Commit

Permalink
fixed null in number json tag string (json-iterator#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaydubina committed Aug 3, 2020
1 parent e28033b commit 3c8ee33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.sum
Expand Up @@ -9,6 +9,7 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLD
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
5 changes: 5 additions & 0 deletions reflect_struct_decoder.go
Expand Up @@ -1075,6 +1075,11 @@ type stringModeNumberDecoder struct {
}

func (decoder *stringModeNumberDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
if iter.WhatIsNext() == NilValue {
decoder.elemDecoder.Decode(ptr, iter)
return
}

c := iter.nextToken()
if c != '"' {
iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c}))
Expand Down
5 changes: 5 additions & 0 deletions value_tests/struct_test.go
Expand Up @@ -26,6 +26,11 @@ func init() {
Field int `json:"field"`
})(nil),
input: `{"field": null}`,
}, unmarshalCase{
ptr: (*struct {
Field int `json:"field,string"`
})(nil),
input: `{"field": null}`,
}, unmarshalCase{
ptr: (*struct {
ID int `json:"id"`
Expand Down

0 comments on commit 3c8ee33

Please sign in to comment.