What version of Go are you using (go version)?
go1.6
What operating system and processor architecture are you using (go env)?
Ubuntu 15.10 amd64
What did you do?
package main
import "fmt"
import "encoding/json"
type t struct {
Test string `json:"test"`
}
func main() {
var test t
err := json.Unmarshal([]byte(`{"test":"good","TEST":"bad"}`), &test)
fmt.Println(test, err)
}
What did you expect to see?
When a struct tag is provided the Unmarshal function shouldn't attempt to do a 'best match' against the field name and should instead only accept keys that exactly match the tag. In this case there is a leading valid field but in the case where there isn't one nothing should be parsed out.
# go run test.go
# {good} <nil>
What did you see instead?
# go run test.go
# {bad} <nil>
The text was updated successfully, but these errors were encountered:
This is the documented behavior, and we can't change it
without breaking the Go 1 compatibility promise.
"To unmarshal JSON into a struct, Unmarshal matches incoming object keys to the keys used by Marshal (either the struct field name or its tag), preferring an exact match but also accepting a case-insensitive match."
go version
)?go1.6
go env
)?Ubuntu 15.10 amd64
When a struct tag is provided the Unmarshal function shouldn't attempt to do a 'best match' against the field name and should instead only accept keys that exactly match the tag. In this case there is a leading valid field but in the case where there isn't one nothing should be parsed out.
The text was updated successfully, but these errors were encountered: