Skip to content

Commit d4196a8

Browse files
committed
add: 添加对自定义time.time类型的支持 零值忽略
1 parent 1ca3a3f commit d4196a8

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

filter/omit_encode.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ TakePointerValue: //取指针的值
2626
}
2727
}
2828

29-
if valueOf.CanConvert(timeTypes) { //是time.Time类型或者底层是time.Time类型
30-
t.Key = key
31-
t.Val = valueOf.Interface()
32-
return
33-
}
34-
3529
if typeOf.NumField() == 0 { //如果是一个struct{}{}类型的字段或者是一个空的自定义结构体编码为{}
3630
t.Key = key
3731
t.Val = struct{}{}
@@ -82,6 +76,11 @@ TakePointerValue: //取指针的值
8276
continue
8377
}
8478
}
79+
if valueOf.CanConvert(timeTypes) { //是time.Time类型或者底层是time.Time类型
80+
t.Key = key
81+
t.Val = valueOf.Interface()
82+
return
83+
}
8584

8685
tree.ParseOmitValue(tag.UseFieldName, omitScene, value.Interface())
8786

filter/select_encode.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package filter
22

33
import (
4-
"fmt"
54
"reflect"
65
"time"
76
)
@@ -34,12 +33,11 @@ TakePointerValue: //取指针的值
3433
}
3534
}
3635

37-
fmt.Println(valueOf.CanConvert(timeTypes))
38-
if valueOf.CanConvert(timeTypes) { //是time.Time类型或者底层是time.Time类型
39-
t.Key = key
40-
t.Val = valueOf.Interface()
41-
return
42-
}
36+
//if valueOf.CanConvert(timeTypes) { //是time.Time类型或者底层是time.Time类型
37+
// t.Key = key
38+
// t.Val = valueOf.Interface()
39+
// return
40+
//}
4341

4442
if typeOf.NumField() == 0 { //如果是一个struct{}{}类型的字段或者是一个空的自定义结构体编码为{}
4543
t.Key = key
@@ -92,6 +90,12 @@ TakePointerValue: //取指针的值
9290
continue
9391
}
9492
}
93+
94+
if valueOf.CanConvert(timeTypes) { //是time.Time类型或者底层是time.Time类型
95+
t.Key = key
96+
t.Val = valueOf.Interface()
97+
return
98+
}
9599
tree.ParseSelectValue(tag.UseFieldName, selectScene, value.Interface())
96100

97101
if t.IsAnonymous {

0 commit comments

Comments
 (0)