-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: support decoding to []int from []string by applying tag ,string #15624
Comments
I believe that this may be affecting the ability to parse JSON responses from the Slack messaging platform. Recently, my go-based Slack bot has been failing to parse the initial response after authenticating, but nothing appears to have changed in the server response and the response does successfully pass jslint. |
I've mailed CL https://go-review.googlesource.com/27453. |
CL https://golang.org/cl/27453 mentions this issue. |
@odeke-em , Thanks for the CL. |
@localvar thanks for taking a look at it, let's put comments on the CL there though. {"i64": ["12", "33", "999"]} and Go code type receiver struct {
I64 []uint64 `json:"i64,string"`
} the data in "i64" will be unmarshaled and assigned to I64. "keys" -> I64 []int `json:"keys,string"` But let's move discussion to the CL itself to avoid noise here but also to ensure that we don't miss out on concerns that should be addressed in the CL. |
@rsc, can I get a JSON decision here? |
This is like fixing someone's wrong JSON by using some magic in tags. This shouldn't be language or core libs part. Rather, if we can attach a field processor |
Hey, is there anything I could do to push this along? I have a few use cases where I need to deal with encoding a slice of uint64's, and am having issues inter-operating with javascript in the browser. I wouldn't like to resort to a typed uint64 and custom (un)marshallers to resolve this encoding issue, if there's a chance we can push this into go 1.12? I see there are a only a couple of code review comments open, and the concerns shouldn't be hard to resolve. Thoughts? |
Due to golang's inability do decode uint64 slice from string slice, we're expecting string input for members (for now): golang/go#15624
Could the issue be pushed along the way? For single id, the ",string" go tag is very nice. However for batch ids request, we need to do a lot more, though we have some ways to solve it, such as implementing the customer type UnmarshalJSON method for []int64 or Int64OrStr. But we need to do these one time by one time for thoses ID requests and for Int64OrStr we need to convert it to Int64 when using Int64OrStr. |
The v2 experiment currently recursively applies the meaning of |
@dsnet does this mean that with json v2 the field like |
Close, but not quite. Since
Thus, we can have |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.6
What operating system and processor architecture are you using (
go env
)?set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\litead\oxygen
set GORACE=
set GOROOT=C:\go
set GOTOOLDIR=C:\go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/A4CLM3P6Dw
What did you expect to see?
decode the int64 slice successfully
What did you see instead?
an error:
according to the documentation, the behavior is correct, but this makes it hard to decode an int64 slice (although there are workarounds). It will be good if 'string' tag could also be applied to slices.
The text was updated successfully, but these errors were encountered: