Hello,
I was wondering why when doing a Marshal and an Unmarshal the numbers are always taken as float64.
Here I put the replication of the error:
package main
import (
"fmt"
"encoding/json"
)
type abc struct {
Name string
Data interface{}
}
func main() {
var idUser int64 = 1
a := abc {
"Abc",
map[string]interface{}{
"id_user": idUser, // string - int64
"name": "a", // string - string
"id_a": 1, // string - int
"id_b": 1.2, // string - float
},
}
b, _ := json.Marshal(a)
// verify types
var data abc
_ = json.Unmarshal(b, &data)
values := data.Data.(map[string]interface{})
for k, v := range values{
fmt.Printf("type key: %T, type value: %T\n", k, v)
}
}
https://play.golang.org/p/Ax014b0JK3E
Would it be a bug in the functions of the json package from go?
Thanks to everyone beforehand