京东JavaDate类型,改为毫秒的timestamp类型兼容处理。
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -411,3 +412,25 @@ func getErrMsgFromData(data map[string]interface{}) string {
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func JavaDateHook(fromType reflect.Type, toType reflect.Type, data interface{}) (interface{}, error) {
|
||||
if (fromType.Kind() >= reflect.Int && fromType.Kind() <= reflect.Uint64) ||
|
||||
fromType.Kind() == reflect.String {
|
||||
if toType.Kind() == reflect.Ptr {
|
||||
toType = toType.Elem()
|
||||
}
|
||||
if toType.Kind() == reflect.Struct &&
|
||||
toType.Name() == "JavaDate" {
|
||||
if sec := utils.Interface2Int64WithDefault(data, 0); sec > 0 {
|
||||
data = utils.NewJavaDateFromTime(utils.Timestamp2Time(sec))
|
||||
} else if fromType.Kind() == reflect.String {
|
||||
data = utils.NewJavaDateFromTime(utils.Str2Time(data.(string)))
|
||||
}
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func JdMap2StructByJson(inObj interface{}, outObjAddr interface{}, weaklyTypedInput bool) (err error) {
|
||||
return utils.Map2Struct(inObj, outObjAddr, true, "", JavaDateHook)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user