0x4a52466c696e74 il y a 2 mois
Parent
commit
2bc5273176
2 fichiers modifiés avec 4 ajouts et 3 suppressions
  1. 1 1
      serialize.go
  2. 3 2
      z_test.go

+ 1 - 1
serialize.go

@@ -74,7 +74,7 @@ func parseType(from, to reflect.Value, fieldName string) IErrorArgs {
 func realValue(val reflect.Value) reflect.Value {
 	if val.Kind() == reflect.Ptr || val.Kind() == reflect.Interface {
 		//if val.Kind() == reflect.Interface {
-		if val.IsNil() && val.Kind() == reflect.Ptr {
+		if val.IsNil() && val.Kind() == reflect.Ptr && val.CanSet() {
 			val.Set(reflect.New(val.Type().Elem()))
 		}
 		// check

+ 3 - 2
z_test.go

@@ -406,6 +406,7 @@ type AuthEmail struct {
 	Email     string `rest:"required" example:"mail@mail.ml"`
 	ThemeName string `rest:"required"`
 	UUser     *User
+	Fields    []any
 }
 
 func (s *AuthEmail) Validate(req IRequestIn) IRequestOut {
@@ -434,8 +435,8 @@ func TestSerializeEmail(t *testing.T) {
 		"email":     "flint@77i.su",
 		"themeName": "th-name",
 		"UUser": json.Map{
-			"ID":       100,
-			"Name":     "User 100",
+			"ID": 100,
+			//"Name":     "User 100",
 			"Created":  "10.11.1983 03:12",
 			"ParentID": nil,
 		},