解决类型反射NPE问题
This commit is contained in:
parent
19813fa9ee
commit
51808626a9
@ -129,7 +129,11 @@ func (df *DataFilter) UserItemToSlice() {
|
||||
//
|
||||
// Date : 2022/1/23 12:45 AM
|
||||
func (df *DataFilter) getValueType(valueResult gjson.Result) string {
|
||||
dataType := reflect.TypeOf(valueResult.Value()).String()
|
||||
dataTypeVal := reflect.TypeOf(valueResult.Value())
|
||||
if nil == dataTypeVal {
|
||||
return "NIL"
|
||||
}
|
||||
dataType := dataTypeVal.String()
|
||||
if strings.Contains(dataType, "int") {
|
||||
return "int64"
|
||||
}
|
||||
@ -243,7 +247,6 @@ func (df *DataFilter) getArrayData(source string, pathArr []string) []gjson.Resu
|
||||
resultList := make([]gjson.Result, 0)
|
||||
dataList := gjson.Get(source, pathArr[0]).Array()
|
||||
for idx := 0; idx < len(dataList); idx++ {
|
||||
// sourceData := gjson.Get(source, dataList[idx].String()).String()
|
||||
resultList = append(resultList, df.getArrayData(dataList[idx].String(), pathArr[1:])...)
|
||||
}
|
||||
return resultList
|
||||
|
@ -267,7 +267,7 @@ func TestDataFilterDiffArr(t *testing.T) {
|
||||
rule := []*FilterDataRule{
|
||||
// {SourceKey: "name", MapKey: "slice.[]", DefaultValue: "用户姓名默认值"},
|
||||
{SourceKey: "table.[].user_list.[].name", MapKey: "user_list.[].detail.name", DefaultValue: "用户姓名默认值"},
|
||||
{SourceKey: "table.[].user_list.[].age", MapKey: "user_list.[]detail.age", DefaultValue: "用户姓名默认值"},
|
||||
{SourceKey: "table.[].user_list.[].age", MapKey: "user_list.[].detail.age", DefaultValue: "用户姓名默认值"},
|
||||
}
|
||||
byteData, _ := json.Marshal(source)
|
||||
filter := NewDataFilter(string(byteData), rule)
|
||||
|
Loading…
Reference in New Issue
Block a user