]> Cypherpunks repositories - gostls13.git/commit
encoding/json: support maps with integer keys
authorCaleb Spare <cespare@gmail.com>
Wed, 13 Apr 2016 23:51:25 +0000 (16:51 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 10 May 2016 03:53:12 +0000 (03:53 +0000)
commitf05c3aa24d815cd3869153750c9875e35fc48a6e
tree224d3057425643cb6ced8fe29a8d26ddc1ca8722
parent9af83462c6f432b77a846a24b4d8efae9bdf0567
encoding/json: support maps with integer keys

This change makes encoding and decoding support integer types in map
keys, converting to/from JSON string keys.

JSON object keys are still sorted lexically, even though the keys may be
integer strings.

For backwards-compatibility, the existing Text(Un)Marshaler support for
map keys (added in CL 20356) does not take precedence over the default
encoding for string types. There is no such concern for integer types,
so integer map key encoding is only used as a fallback if the map key
type is not a Text(Un)Marshaler.

Fixes #12529.

Change-Id: I7e68c34f9cd19704b1d233a9862da15fabf0908a
Reviewed-on: https://go-review.googlesource.com/22060
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/encoding/json/decode.go
src/encoding/json/decode_test.go
src/encoding/json/encode.go