处理数组结构体

This commit is contained in:
yun
2025-09-20 21:17:17 +08:00
parent 0b7a1cf46d
commit 02152b44bf
2 changed files with 283 additions and 136 deletions
+5 -4
View File
@@ -463,10 +463,10 @@ func TestAttactToStruct_ErrorScenarios(t *testing.T) {
expectedErr: "需要是非空指针",
},
{
name: "不支持的类型",
name: "自定义类型",
structPtr: &struct{ Data []string }{},
input: map[string]string{"data": "test"},
expectedErr: "不支持的类型",
input: map[string]string{"Data": `["test","test2"]`},
expectedErr: "",
},
{
name: "无效的嵌套路径",
@@ -475,7 +475,7 @@ func TestAttactToStruct_ErrorScenarios(t *testing.T) {
"nonexistent.field": "value",
"basic.name": "test",
},
expectedErr: "", // 应该忽略不存在的字段而不报错
expectedErr: "字段 nonexistent.field 不存在", // 应该忽略不存在的字段而不报错
},
}
@@ -592,6 +592,7 @@ func BenchmarkAttactToStruct_Nested(b *testing.B) {
"basic.salary": "50000.0",
"basic.is_active": "true",
"comment": "test",
"amount": "500.0",
}
b.ResetTimer()