diff --git a/scaner_test.go b/scaner_test.go index 21410548..cd89ca49 100644 --- a/scaner_test.go +++ b/scaner_test.go @@ -3,6 +3,7 @@ package gorm_test import ( "database/sql/driver" "encoding/json" + "errors" "testing" ) @@ -51,7 +52,14 @@ func (l ExampleStringSlice) Value() (driver.Value, error) { } func (l *ExampleStringSlice) Scan(input interface{}) error { - return json.Unmarshal(input.([]byte), l) + switch value := input.(type) { + case string: + return json.Unmarshal([]byte(value), l) + case []byte: + return json.Unmarshal(value, l) + default: + return errors.New("not supported") + } } type ExampleStruct struct { @@ -66,5 +74,12 @@ func (l ExampleStructSlice) Value() (driver.Value, error) { } func (l *ExampleStructSlice) Scan(input interface{}) error { - return json.Unmarshal(input.([]byte), l) + switch value := input.(type) { + case string: + return json.Unmarshal([]byte(value), l) + case []byte: + return json.Unmarshal(value, l) + default: + return errors.New("not supported") + } }