Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
What operating system and processor architecture are you using (go env)?
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
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?
json: cannot unmarshal string into Go value of type int64
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:
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.
@odeke-em , Thanks for the CL.
If I'm reading the code correct, tags like json:"i64" is used in the fix, this seems not consistent with other tags, for example when we want an int64, we use: json:",string"
@localvar thanks for taking a look at it, let's put comments on the CL there though.
But anyways, am using "i64" as the key and not as the auxilliary tag; it is so that the respective Go struct attribute will receive the unmarshaled data of json data key "i64", so
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 func, where we get raw bytes and json field tag and do our work explicitly and then return expected type value or error. The returned post-processed value will then be assigned to that field by JSON unmarshaller.