You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
version 1.9
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env)?
windows/amd64
What did you do?
package main
import (
"encoding/json"
"fmt"
)
type A struct {
X int `json:",string"`
Y uintptr `json:",string"`
Z B
}
type B map[uintptr]string
func main() {
s := new(A)
s.Z = make(B)
s.Z[0] = ""
r, _ := json.Marshal(s)
fmt.Println(string(r))
}
What did you expect to see?
{"X":"0","Y":"0","Z":{"0":""}}
What did you see instead?
{"X":"0","Y":0,"Z":{"0":""}}
Issue
As required by the json.Marshal documentation, the Y field of uintptr type, marked with the json tag "string" option, should be marshalled as JSON string, not JSON number.
Please note that the X field, of integer int type, and the map's key of the Z field, of integer uintptr type, are both marshalled as JSON string, as expected by the documentation, that states:
The "string" option signals that a field is stored as JSON inside a JSON-encoded string. It applies only to fields of string, floating point, integer, or boolean types.
The map's key type must either be a string, an integer type, or implement encoding.TextMarshaler.
Proposal
At line 1138 of of encoding/json/encode.go, please add reflect.Uintptr to the list of types that can be encoded to JSON string by the "string" option.
The text was updated successfully, but these errors were encountered:
gbbr
changed the title
integer type uintptr not marshalled to JSON string with "string" option
encoding/json: integer type uintptr not marshalled with "string" option
Nov 8, 2017
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?version 1.9
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?windows/amd64
What did you do?
What did you expect to see?
{"X":"0","Y":"0","Z":{"0":""}}
What did you see instead?
{"X":"0","Y":0,"Z":{"0":""}}
Issue
Please note that the X field, of integer
int
type, and the map's key of the Z field, of integeruintptr
type, are both marshalled as JSON string, as expected by the documentation, that states:The "string" option signals that a field is stored as JSON inside a JSON-encoded string. It applies only to fields of string, floating point, integer, or boolean types.
The map's key type must either be a string, an integer type, or implement encoding.TextMarshaler.
Proposal
The text was updated successfully, but these errors were encountered: