feat: fix UnixSecondSerializer return nil
This commit is contained in:
parent
985dcdc8a7
commit
f29e9d2485
@ -122,6 +122,9 @@ func (UnixSecondSerializer) Value(ctx context.Context, field *Field, dst reflect
|
||||
switch v := fieldValue.(type) {
|
||||
case int64, int, uint, uint64, int32, uint32, int16, uint16, *int64, *int, *uint, *uint64, *int32, *uint32, *int16, *uint16:
|
||||
rv := reflect.ValueOf(v)
|
||||
if rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||
return nil, nil
|
||||
}
|
||||
if rv.IsZero() {
|
||||
return time.Unix(0, 0), nil
|
||||
}
|
||||
|
@ -131,19 +131,7 @@ func TestSerializerZeroValue(t *testing.T) {
|
||||
t.Fatalf("no error should happen when migrate scanner, valuer struct, got error %v", err)
|
||||
}
|
||||
|
||||
createdAt := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
updatedAt := createdAt.Unix()
|
||||
|
||||
data := SerializerStruct{
|
||||
Name: []byte("jinzhu"),
|
||||
Roles: []string{"r1", "r2"},
|
||||
Contracts: map[string]interface{}{"name": "jinzhu", "age": 10},
|
||||
EncryptedString: EncryptedString("pass"),
|
||||
CreatedTime: createdAt.Unix(),
|
||||
UpdatedTime: &updatedAt,
|
||||
JobInfo: Job{},
|
||||
CustomSerializerString: "world",
|
||||
}
|
||||
data := SerializerStruct{}
|
||||
|
||||
if err := DB.Create(&data).Error; err != nil {
|
||||
t.Fatalf("failed to create data, got error %v", err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user