update serialize

This commit is contained in:
2024-10-24 21:57:29 +08:00
parent d87fb61db5
commit e5b2e1a377
4 changed files with 22 additions and 12 deletions

View File

@ -129,7 +129,7 @@ func handleSliceSlice(inputValue interface{}, rule *define.FieldRule) ([][]any,
}
sliceSlice := make([][]any, 0)
for _, item := range anySlice {
byteData := serialize.JSON.MarshalForByte(item)
byteData := serialize.JSON.MarshalForByteIgnoreError(item)
res := make([]any, 0)
if err = serialize.JSON.UnmarshalWithNumber(byteData, &res); nil != err {
return nil, fmt.Errorf("%v : data type is expect [][]any, but convert fail : %v", rule.Path, err.Error())
@ -154,7 +154,7 @@ func handleSliceMapAny(inputValue interface{}, rule *define.FieldRule) ([]map[an
}
mapSlice := make([]map[any]any, 0)
for _, item := range anySlice {
byteData := serialize.JSON.MarshalForByte(item)
byteData := serialize.JSON.MarshalForByteIgnoreError(item)
jsonRes := gjson.ParseBytes(byteData)
res := make(map[any]any)
jsonRes.ForEach(func(key, value gjson.Result) bool {
@ -181,7 +181,7 @@ func handleSliceMapString(inputValue interface{}, rule *define.FieldRule) ([]map
}
mapSlice := make([]map[string]any, 0)
for _, item := range anySlice {
byteData := serialize.JSON.MarshalForByte(item)
byteData := serialize.JSON.MarshalForByteIgnoreError(item)
jsonRes := gjson.ParseBytes(byteData)
res := make(map[string]any)
jsonRes.ForEach(func(key, value gjson.Result) bool {
@ -204,7 +204,7 @@ func handleSlice(inputValue interface{}, rule *define.FieldRule) ([]any, error)
return nil, fmt.Errorf("%v : data type is expect slice or string, but get %v", rule.Path, inputValType.String())
}
if inputValType == reflect.Slice {
inputValue = serialize.JSON.MarshalForString(inputValue)
inputValue = serialize.JSON.MarshalForStringIgnoreError(inputValue)
// 重置配置
if nil == rule.SliceConfig {
rule.SliceConfig = &define.SliceConfig{