京东JavaDate类型,改为毫秒的timestamp类型兼容处理。

This commit is contained in:
gazebo
2019-11-15 15:18:29 +08:00
parent 74d40eb1fd
commit 57d00d1bc7
12 changed files with 161 additions and 32 deletions

View File

@@ -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)
}