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: structs in Json Decode improperly applied #22307

Closed
patientplatypus opened this issue Oct 17, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@patientplatypus
Copy link

commented Oct 17, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/patientplatypus/Documents/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0q/_p03fcl11012llbls0r0bwp00000gn/T/go-build986239688=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
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"

The issue.

On the front I send a POST request with {charactername: "Frodo"}

type Character struct {
	Charactername string
}

function IO(r, w){
        var incomingjson Character
	log.Print("value of r.Body: ", r.Body)
	decoder := json.NewDecoder(r.Body)
	log.Print("after json decoder")
	err := decoder.Decode(&incomingjson)
        charactername = incomingjson.Character
        log.Print(charactername)
}

This prints "".

However if I use

type Character struct {
	Charactername string
        Garbagevariable whatevertype
}

It will print "Frodo".

This is an annoying bug that cost me time. Please fix this

@ALTree ALTree changed the title Structs in Json Decode Improperly Applied (Bug - Please Fix) encoding/json: structs in Json Decode improperly applied Oct 17, 2017

@ALTree

This comment has been minimized.

Copy link
Member

commented Oct 17, 2017

Would you be able to provide a runnable reproducer? Your report does not contain a valid, complete, go program.

@davecheney

This comment has been minimized.

Copy link
Contributor

commented Oct 19, 2017

I’m sorry this is not a valid bug report. You haven’t handled the error from decode and the input data you provided is not valid json.

@gopherbot

This comment has been minimized.

Copy link

commented Nov 19, 2017

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.)

@gopherbot gopherbot closed this Nov 19, 2017

@golang golang locked and limited conversation to collaborators Nov 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.