feat(serialization): add validation support for custom slice types

Enhanced the ConvertSlice function to include validation for destination slices that implement the CustomValidator interface. If validation fails, errors are collected and returned, ensuring data integrity during slice conversion.
This commit is contained in:
yusing
2026-01-10 15:49:58 +08:00
committed by github-actions[bot]
parent fd7f7081bc
commit a0c43ee93e

View File

@@ -480,6 +480,14 @@ func ConvertSlice(src reflect.Value, dst reflect.Value, checkValidateTag bool) g
}
numValid++
}
if dst.Type().Implements(reflect.TypeFor[CustomValidator]()) {
err := dst.Interface().(CustomValidator).Validate()
if err != nil {
sliceErrs.Add(err)
}
}
if err := sliceErrs.Error(); err != nil {
dst.SetLen(numValid) // shrink to number of elements that were successfully converted
return err