Skip to content
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: slice of struct is unmarshalled to slice of map #21429

Closed
localvar opened this issue Aug 14, 2017 · 1 comment
Closed

encoding/json: slice of struct is unmarshalled to slice of map #21429

localvar opened this issue Aug 14, 2017 · 1 comment

Comments

@localvar
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.8.3

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/oxygen"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build497237388=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

https://play.golang.org/p/INLJG6msgi

What did you expect to see?

test1 outputs a slice of struct

What did you see instead?

test1 outputs a slice of map

@mvdan
Copy link
Member

mvdan commented Aug 14, 2017

test1 is unmarshaling into interface{}. All it can do at that point is types like []interface{} and map[string]interface{}. See https://golang.org/pkg/encoding/json/#Unmarshal.

And for questions about Go, see https://golang.org/wiki/Questions.

@mvdan mvdan closed this as completed Aug 14, 2017
@golang golang locked and limited conversation to collaborators Aug 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants