Open
Description
This is a follow-up to #152, because the proposed "solution" / workaround doesn't work. The ticket was already closed though.
In PostgreSQL, the column has type JSONB.
go (simplified):
type ArgumentList []interface{}
func (a ArgumentList) Value() (driver.Value, error) {
js, _ := a.MarshalJSON() // Returns a json-array. Nil-slices return "[]".
return datatypes.JSON(js).Value()
}
func (a *ArgumentList) Scan(value interface{}) error {
var js datatypes.JSON
js.Scan(value)
return json.Unmarshal(js, a)
}
func (ArgumentList) GormDataType() string {
return datatypes.JSON{}.GormDataType()
}
func (ArgumentList) GormDBDataType(db *gorm.DB, field *schema.Field) string {
return datatypes.JSON{}.GormDBDataType(db, field)
}
I'm already using datatypes.JSON in my custom serializer / scanner, as proposed by the other ticket.
However, they are never called for nil-slices.
Before 1.4.6, my serializers converted nil-slices to empty json-arrays.
Now, they are ignored, nil gets converted into a PostgreSQL null, and my not-null-constraints are triggered.
So this is definitely a breaking change.
Metadata
Metadata
Assignees
Labels
No labels