I have struct, that is model for table. All was good, until I want to add type struct into it and serialize it to json (Location).
type Dome struct {
gorm.Model
Location Location `json:"location" gorm:"serializer:json"`
Title string `json:"title" gorm:"type:varchar(100)"`
}
type Location struct {
X1 int
Y1 int
X2 int
Y2 int
}
When doing .Updates(), those values are serialized and saved into column. But when doing Create or Save, it throw error
sql: converting argument $ type: unsupported type Location, a struct
From what I understood, Gorm already have some default serializers, like json. And it seems to work on Updates, but not on any Create. Also when debugging I see those values deserialized and again in struct.
I can't find answer what am I missing, maybe need to add something else, but I am not that experienced. How to do that serialization into column from struct using Gorm?
