修复validate path错误问题

This commit is contained in:
白茶清欢 2025-03-31 17:15:45 +08:00
parent 3814638e1c
commit b9b1cba508

View File

@ -20,7 +20,6 @@ import (
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
"strings"
jsonFilter "git.zhangdeman.cn/zhangdeman/json_filter"
)
var validatorInstance *validator.Validate
@ -36,23 +35,8 @@ func init() {
//
// Date : 15:12 2025/3/18
func Run(sourceData []byte, fieldList []StructField) ([]byte, error) {
mapRuleList := make([]jsonFilter.MapRule, 0)
for _, itemParam := range fieldList {
mapRuleList = append(mapRuleList, jsonFilter.MapRule{
SourcePath: itemParam.SourcePath,
TargetPath: itemParam.TargetPath,
Required: false,
DataType: itemParam.Type,
DefaultValue: itemParam.DefaultValue,
})
}
filterInstance := jsonFilter.NewFilter(string(sourceData), mapRuleList)
if err := filterInstance.Deal(); nil != err {
return nil, err
}
formatByteData := filterInstance.Byte()
handleInstance := &handle{
sourceData: formatByteData,
sourceData: sourceData,
fieldList: fieldList,
parentFieldTable: map[string]bool{},
}
@ -118,7 +102,11 @@ func (h *handle) Run() ([]byte, error) {
// 支持嵌套结构体
fieldTag := h.generateTag(field)
// 这里需要设置为对应类型的零值就行, 此处传入值的目的只是为了确认数据类型
h.dynamicStruct.AddField(field.JsonTag, "", consts.GetDataTypeDefaultValue(field.Type), fieldTag, false)
path := field.TargetPath
if path == "" {
path = field.JsonTag
}
h.dynamicStruct.AddField(path, "", consts.GetDataTypeDefaultValue(field.Type), fieldTag, false)
}
val := h.dynamicStruct.Build().New()
if err := serialize.JSON.UnmarshalWithNumber([]byte(h.formatVal), &val); nil != err {