mirror of
https://github.com/golang/go
synced 2024-11-19 17:44:43 -07:00
encoding/json: permit encoding uintptr as a string
Fixes #22629 Change-Id: I31e85f9faa125ee0dfd6d3c5fa89334b00d61e6e Reviewed-on: https://go-review.googlesource.com/76530 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Joe Tsai <joetsai@google.com>
This commit is contained in:
parent
65a864a628
commit
ed3d672766
@ -1193,7 +1193,8 @@ type All struct {
|
|||||||
Foo string `json:"bar"`
|
Foo string `json:"bar"`
|
||||||
Foo2 string `json:"bar2,dummyopt"`
|
Foo2 string `json:"bar2,dummyopt"`
|
||||||
|
|
||||||
IntStr int64 `json:",string"`
|
IntStr int64 `json:",string"`
|
||||||
|
UintptrStr uintptr `json:",string"`
|
||||||
|
|
||||||
PBool *bool
|
PBool *bool
|
||||||
PInt *int
|
PInt *int
|
||||||
@ -1247,24 +1248,25 @@ type Small struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var allValue = All{
|
var allValue = All{
|
||||||
Bool: true,
|
Bool: true,
|
||||||
Int: 2,
|
Int: 2,
|
||||||
Int8: 3,
|
Int8: 3,
|
||||||
Int16: 4,
|
Int16: 4,
|
||||||
Int32: 5,
|
Int32: 5,
|
||||||
Int64: 6,
|
Int64: 6,
|
||||||
Uint: 7,
|
Uint: 7,
|
||||||
Uint8: 8,
|
Uint8: 8,
|
||||||
Uint16: 9,
|
Uint16: 9,
|
||||||
Uint32: 10,
|
Uint32: 10,
|
||||||
Uint64: 11,
|
Uint64: 11,
|
||||||
Uintptr: 12,
|
Uintptr: 12,
|
||||||
Float32: 14.1,
|
Float32: 14.1,
|
||||||
Float64: 15.1,
|
Float64: 15.1,
|
||||||
Foo: "foo",
|
Foo: "foo",
|
||||||
Foo2: "foo2",
|
Foo2: "foo2",
|
||||||
IntStr: 42,
|
IntStr: 42,
|
||||||
String: "16",
|
UintptrStr: 44,
|
||||||
|
String: "16",
|
||||||
Map: map[string]Small{
|
Map: map[string]Small{
|
||||||
"17": {Tag: "tag17"},
|
"17": {Tag: "tag17"},
|
||||||
"18": {Tag: "tag18"},
|
"18": {Tag: "tag18"},
|
||||||
@ -1326,6 +1328,7 @@ var allValueIndent = `{
|
|||||||
"bar": "foo",
|
"bar": "foo",
|
||||||
"bar2": "foo2",
|
"bar2": "foo2",
|
||||||
"IntStr": "42",
|
"IntStr": "42",
|
||||||
|
"UintptrStr": "44",
|
||||||
"PBool": null,
|
"PBool": null,
|
||||||
"PInt": null,
|
"PInt": null,
|
||||||
"PInt8": null,
|
"PInt8": null,
|
||||||
@ -1418,6 +1421,7 @@ var pallValueIndent = `{
|
|||||||
"bar": "",
|
"bar": "",
|
||||||
"bar2": "",
|
"bar2": "",
|
||||||
"IntStr": "0",
|
"IntStr": "0",
|
||||||
|
"UintptrStr": "0",
|
||||||
"PBool": true,
|
"PBool": true,
|
||||||
"PInt": 2,
|
"PInt": 2,
|
||||||
"PInt8": 3,
|
"PInt8": 3,
|
||||||
|
@ -1131,7 +1131,7 @@ func typeFields(t reflect.Type) []field {
|
|||||||
switch ft.Kind() {
|
switch ft.Kind() {
|
||||||
case reflect.Bool,
|
case reflect.Bool,
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
|
||||||
reflect.Float32, reflect.Float64,
|
reflect.Float32, reflect.Float64,
|
||||||
reflect.String:
|
reflect.String:
|
||||||
quoted = true
|
quoted = true
|
||||||
|
@ -71,14 +71,16 @@ func TestOmitEmpty(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StringTag struct {
|
type StringTag struct {
|
||||||
BoolStr bool `json:",string"`
|
BoolStr bool `json:",string"`
|
||||||
IntStr int64 `json:",string"`
|
IntStr int64 `json:",string"`
|
||||||
StrStr string `json:",string"`
|
UintptrStr uintptr `json:",string"`
|
||||||
|
StrStr string `json:",string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var stringTagExpected = `{
|
var stringTagExpected = `{
|
||||||
"BoolStr": "true",
|
"BoolStr": "true",
|
||||||
"IntStr": "42",
|
"IntStr": "42",
|
||||||
|
"UintptrStr": "44",
|
||||||
"StrStr": "\"xzbit\""
|
"StrStr": "\"xzbit\""
|
||||||
}`
|
}`
|
||||||
|
|
||||||
@ -86,6 +88,7 @@ func TestStringTag(t *testing.T) {
|
|||||||
var s StringTag
|
var s StringTag
|
||||||
s.BoolStr = true
|
s.BoolStr = true
|
||||||
s.IntStr = 42
|
s.IntStr = 42
|
||||||
|
s.UintptrStr = 44
|
||||||
s.StrStr = "xzbit"
|
s.StrStr = "xzbit"
|
||||||
got, err := MarshalIndent(&s, "", " ")
|
got, err := MarshalIndent(&s, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user