In the below code:
type Column2Type []*T
type T struct {
ID int `json:"id"`
CreatedAt Timestamp `json:"created_at"`
}
t, _ := time.Parse("2006-01-02T15:04:05", "2024-06-25T04:33:55")
// helper function to fill column 2
getColumn2 := func() []byte {
c := Column2Type{
&T{
ID: 2,
CreatedAt: Timestamp{Time: t},
},
}
b, err := json.Marshal(c)
if err != nil {
panic(err)
}
fmt.Println(c[0].CreatedAt). // 2024-06-25 04:33:55 +0000 UTC
fmt.Println(string(b)) // has extra text "Z" - [{"id":2,"created_at":"2024-06-25T04:33:55Z"}]
return b
}
Implication:
Table row scanning for column ‘col_2_name’ gives error: parsing time "2024-06-25T04:33:55Z": extra text: "Z"
How to avoid json.Marshal() to add timezone Z?