mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
fixed slice deserialization
This commit is contained in:
parent
0aa00ab226
commit
0995c8b839
1 changed files with 18 additions and 3 deletions
|
@ -244,8 +244,12 @@ func Deserialize(src SerializedObject, dst any) E.Error {
|
|||
if e.Param() != "" {
|
||||
detail += ":" + e.Param()
|
||||
}
|
||||
fieldName, ok := fieldName[e.Field()]
|
||||
if !ok {
|
||||
fieldName = e.Field()
|
||||
}
|
||||
errs.Add(ErrValidationError.
|
||||
Subject(fieldName[e.Field()]).
|
||||
Subject(fieldName).
|
||||
Withf("require %q", detail))
|
||||
}
|
||||
}
|
||||
|
@ -424,8 +428,19 @@ func ConvertString(src string, dst reflect.Value) (convertible bool, convErr E.E
|
|||
switch dst.Kind() {
|
||||
case reflect.Slice:
|
||||
// one liner is comma separated list
|
||||
if len(lines) == 0 {
|
||||
dst.Set(reflect.ValueOf(strutils.CommaSeperatedList(src)))
|
||||
if len(lines) == 1 {
|
||||
values := strutils.CommaSeperatedList(src)
|
||||
dst.Set(reflect.MakeSlice(dst.Type(), len(values), len(values)))
|
||||
errs := E.NewBuilder("invalid slice values")
|
||||
for i, v := range values {
|
||||
err := Convert(reflect.ValueOf(v), dst.Index(i))
|
||||
if err != nil {
|
||||
errs.Add(err.Subjectf("[%d]", i))
|
||||
}
|
||||
}
|
||||
if errs.HasError() {
|
||||
return true, errs.Error()
|
||||
}
|
||||
return
|
||||
}
|
||||
sl := make([]string, 0, len(lines))
|
||||
|
|
Loading…
Add table
Reference in a new issue