encoding/json: encode map key is of string kind, decode only of string type #3519
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
The text was updated successfully, but these errors were encountered:
This issue was closed.