|
@@ -169,6 +169,11 @@ func parseName(val reflect.Value) (res *Field, err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func StructTypeName(val reflect.Value) string {
|
|
|
|
+ t := val.Type()
|
|
|
|
+ return t.PkgPath() + "." + t.Name()
|
|
|
|
+}
|
|
|
|
+
|
|
func fieldVal(val reflect.Value, fieldName string, files RequestFiles, names FieldList) (res reflect.Value, err IErrorArgs) {
|
|
func fieldVal(val reflect.Value, fieldName string, files RequestFiles, names FieldList) (res reflect.Value, err IErrorArgs) {
|
|
switch val.Kind() {
|
|
switch val.Kind() {
|
|
case reflect.Ptr, reflect.Interface:
|
|
case reflect.Ptr, reflect.Interface:
|
|
@@ -193,6 +198,11 @@ func fieldVal(val reflect.Value, fieldName string, files RequestFiles, names Fie
|
|
return reflect.ValueOf(rVal), nil
|
|
return reflect.ValueOf(rVal), nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ // check public fields exists
|
|
|
|
+ if val.NumField() == 0 {
|
|
|
|
+ res = reflect.ValueOf(fmt.Sprint(val.Interface()))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
// parse struct public fields
|
|
// parse struct public fields
|
|
if len(names) == 0 {
|
|
if len(names) == 0 {
|
|
names = fieldsDefault(val.Type())
|
|
names = fieldsDefault(val.Type())
|
|
@@ -225,7 +235,13 @@ func fieldVal(val reflect.Value, fieldName string, files RequestFiles, names Fie
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
if fVal.IsValid() {
|
|
if fVal.IsValid() {
|
|
- jm[name.Name] = fVal.Interface()
|
|
|
|
|
|
+ stn := StructTypeName(field)
|
|
|
|
+ con, check := fieldConverters[stn]
|
|
|
|
+ if check {
|
|
|
|
+ jm[name.Name] = con.Pack(field.Interface())
|
|
|
|
+ } else {
|
|
|
|
+ jm[name.Name] = fVal.Interface()
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
jm[name.Name] = nil
|
|
jm[name.Name] = nil
|
|
}
|
|
}
|
|
@@ -360,12 +376,3 @@ func OutFields(req IRequestIn, obj any, files RequestFiles, names FieldList) IRe
|
|
}
|
|
}
|
|
return req.OutSuccess(m, files)
|
|
return req.OutSuccess(m, files)
|
|
}
|
|
}
|
|
-
|
|
|
|
-/*
|
|
|
|
-func OutFieldsReq(req IRequestIn, obj any, files RequestFiles, names FieldList) IRequestOut {
|
|
|
|
- if len(names) == 0 {
|
|
|
|
- names = req.Fields()
|
|
|
|
- }
|
|
|
|
- return OutFields(req, obj, files, names)
|
|
|
|
-}
|
|
|
|
-*/
|
|
|