Compare commits

..

No commits in common. "main" and "v1.0.0" have entirely different histories.
main ... v1.0.0

9
api.go
View File

@ -3,7 +3,6 @@ package structmapper
import (
"encoding/json"
"fmt"
"reflect"
di "git.apihub24.de/admin/generic-di"
"git.apihub24.de/admin/structmapper/utils"
@ -53,14 +52,10 @@ func SliceMap[TFrom any, TTo any](from []TFrom) []TTo {
func AutoMap[TFrom any, TTo any](from TFrom) (TTo, error) {
var result TTo
resultValue := reflect.ValueOf(&result).Elem()
if resultValue.Kind() == reflect.Ptr {
resultValue.Set(reflect.New(resultValue.Type().Elem()))
}
str, err := json.Marshal(from)
if err != nil {
return result, err
}
err = json.Unmarshal(str, resultValue.Addr().Interface())
return result, err
_ = json.Unmarshal(str, &result)
return result, nil
}