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
Closed

encoding/json: structs in Json Decode improperly applied #22307

patientplatypus opened this issue Oct 17, 2017 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@patientplatypus
Copy link

patientplatypus 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
Copy link
Member

ALTree commented Oct 17, 2017

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

@davecheney
Copy link
Contributor

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.

@davecheney davecheney added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 19, 2017
@gopherbot
Copy link

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

@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.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants