Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion automapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func MapLoose(source, dest interface{}) {

func mapValues(sourceVal, destVal reflect.Value, loose bool) {
destType := destVal.Type()
if destType.Kind() == reflect.Struct && !sourceTypeEqualsDestType(sourceVal, destVal) {
if destType.Kind() == reflect.Struct && sourceVal.Type() != destVal.Type() {
if sourceVal.Type().Kind() == reflect.Ptr {
if sourceVal.IsNil() {
// If source is nil, it maps to an empty struct
Expand Down
10 changes: 5 additions & 5 deletions automapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ func TestWithLooseOption(t *testing.T) {
assert.Equal(t, dest.Bar, 0)
}

func TestStructCanBeSet(t *testing.T) {
type MainType struct {
func TestSetStructOfSameTypeDirectly(t *testing.T) {
type FooType struct {
time.Time
}
source := struct {
Foo MainType
}{MainType{Time: time.Now().UTC()}}
Foo FooType
}{FooType{Time: time.Now().UTC()}}
dest := struct {
Foo MainType
Foo FooType
}{}
Map(&source, &dest)
assert.Equal(t, source.Foo.String(), dest.Foo.String())
Expand Down