New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encoding/json: Unmarshal does not return error on ambiguous input #19194
Comments
Another interesting effect is that Playground: https://play.golang.org/p/REonDIbRan Is this the expected behaviour? |
There seems to at least be some documentation missing. Leaving for @rsc. |
Kindly requesting your input here @rsc. |
I'm not sure if I see a bug here. It seems to me that Have you read this part of the
In the original sample, what's happening is that there are multiple conflicting JSON-tagged fields. Therefore, the last rule applies. All fields are ignored, no error occurs. Do you see anything wrong with my analysis? |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/sarath/go"
GORACE=""
GOROOT="/home/sarath/goroot"
GOTOOLDIR="/home/sarath/goroot/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build040972726=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
Created two structs with one field same in both and embedded both to a new struct
Eg:
Tried to assign C.X , it failed as expected with expected error
ambiguous selector c.X
Tried to unmarshal a JSON to
C
.It did not assign value to X but did not return any error ,which is unexpectedHere is the playground link : https://play.golang.org/p/SUlPSC2y3F
What did you expect to see?
Expected error to return on json.Unmarshal
What did you see instead?
No error returned and no field assignments either
The text was updated successfully, but these errors were encountered: