Przeglądaj źródła

fixed null in number json tag string (#480)

Nikolay Dubina 5 lat temu
rodzic
commit
9461257643
3 zmienionych plików z 11 dodań i 0 usunięć
  1. 1 0
      go.sum
  2. 5 0
      reflect_struct_decoder.go
  3. 5 0
      value_tests/struct_test.go

+ 1 - 0
go.sum

@@ -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 - 0
reflect_struct_decoder.go

@@ -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}))

+ 5 - 0
value_tests/struct_test.go

@@ -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"`