vet at tip detects duplicate struct tags (#17599).
quentinmit
changed the title
encoding/json encoding duplicate struct keys fail silently (and does not report error)
encoding/json: encoding duplicate struct keys fail silently (and does not report error)
Nov 15, 2016
When due to a bug a structure has two fields with the same key like:
The JSON marshaller will silently ignore the fields. I would expect it to return an error to the caller.
Example program: https://play.golang.org/p/DOUbRT9k_U
What version of Go are you using (
go version
)?go version go1.7 darwin/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/moshe/Documents/code/gopath"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y6/cd3mw6tx1qn89g0vn2pdz4gc0000gn/T/go-build725917179=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
What did you do?
https://play.golang.org/p/DOUbRT9k_U
What did you expect to see?
I expected to get an error from json.Marshal
What did you see instead?
No error and no encoding
The text was updated successfully, but these errors were encountered: