You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
maja42
changed the title
Breaking change since 1.4.6: Serializing nil-Slices to JSONB
Breaking change since 1.4.6: nil-Slices with custom driver.Valuer / sql.Scanner
Feb 15, 2023
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):
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.
The text was updated successfully, but these errors were encountered: