encoding/json: Unmarshal replaces interface{} types instead of acting on the underlying type #20994
Milestone
Comments
The target value is an interface, not a map (even though the concrete type happens to be a map for the second call). Therefore only the first bit of documentation you quoted applies, not the second. I think the behavior is as intended, but the documentation could be a bit more explicit. |
I was confused about |
The behavior is intended and I think pretty explicit. The text says "Unmarshal stores one of these in the interface value:" and so it does. I don't think there's more to say here that's useful. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8.3 darwin/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
What did you do?
Unmarshal to existing
map[string]interface{}
that is hidden behind aninterface{}
:https://play.golang.org/p/kgaRznDOwb
What did you expect to see?
First:
map[A:B]
Second:
map[A:B C:D]
According to docs:
I expect unmarshal to reuse the existing map, instead of replacing it.
What did you see instead?
First:
map[A:B]
Second:
map[C:D]
The text was updated successfully, but these errors were encountered: