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: encode map key is of string kind, decode only of string type #3519

Closed
gopherbot opened this issue Apr 13, 2012 · 6 comments
Closed
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@gopherbot
Copy link

by acmmlyc:

There's an asymmetry that's bugging me—I don't know if you care enough to have it
fixed, but it tripped me up, so it may be worth.

Encoding a map fails if v.Type().Key().Kind() != reflect.String, meaning the string type
*and* any synonym thereof (constructed with type X string) will work as a key.

Conversely, decoding fails if t := v.Type(); t.Key() != reflect.TypeOf(""),
forcing a string type rather than string kind.

Small demonstration here: http://play.golang.org/p/Jcl_elUQNx

Encode produces sensible JSON, but decode doesn't mutate the map.

Ideally it'd be consistent one way or another; by encoding rejecting anything not a
"string" type, or decoding accepting non-"string"-typed
string-kinds! If you think this is sensible, I'd be happy to try to hack a patch
together.

Cheers,

Arlen
@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 1:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 2:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 3:

Labels changed: added size-m.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 4:

Labels changed: added suggested.

@davecheney
Copy link
Contributor

Comment 5:

This issue was closed by revision a460012.

Status changed to Fixed.

@gopherbot
Copy link
Author

Comment 6 by ar@len.me:

Thanks!

@gopherbot gopherbot added fixed Suggested Issues that may be good for new contributors looking for work to do. labels Dec 30, 2012
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

3 participants