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: custom type marshaling doesn't work for map values #55890

Open
friedrichsenm opened this issue Sep 27, 2022 · 2 comments
Open
Labels
NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@friedrichsenm
Copy link

friedrichsenm commented Sep 27, 2022

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

$ go version 1.16

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/matt/.cache/go-build"
GOENV="/home/matt/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/matt/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/matt/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/matt/sdk/go1.19.1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/matt/sdk/go1.19.1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/matt/GitHub/relay_common/smm_api/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2596506419=/tmp/go-build -gno-record-gcc-switches"

What did you do?

If you define custom marshaling/unmarshaling functions for a type, json.Marshal doesn't use them when the custom type is used as value in a map.

https://go.dev/play/p/uggz6OAQo_J

What did you expect to see?

I expect the custom type marshaling functions to be respected even when the custom type is a value in a map

What did you see instead?

JSON reverts to a default marshaling/unmarshaling function

@panjf2000 panjf2000 added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 27, 2022
@panjf2000
Copy link
Member

panjf2000 commented Sep 27, 2022

cc @mvdan

@dsnet
Copy link
Member

dsnet commented Sep 27, 2022

This is a known problem. It is related to but not quite identical to #33993 and #22967.

Fundamentally, the issue is that the "encoding/json" package has an non-addressable value on hand, and so it can't call a pointer method. There are ways to resolve this in the internal implementation of "json", but doing so has historically proven to be a breaking change.

@dsnet dsnet removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 27, 2022
@dmitshur dmitshur added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 27, 2022
@dmitshur dmitshur added this to the Backlog milestone Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

4 participants