fix type identification when object indexed is pointer to struct
fixes #508
This commit is contained in:
parent
d4f21a6290
commit
3b2bc30b54
|
@ -51,6 +51,11 @@ func lookupPropertyPathPart(data interface{}, part string) interface{} {
|
||||||
if field.IsValid() && field.CanInterface() {
|
if field.IsValid() && field.CanInterface() {
|
||||||
return field.Interface()
|
return field.Interface()
|
||||||
}
|
}
|
||||||
|
case reflect.Ptr:
|
||||||
|
ptrElem := val.Elem()
|
||||||
|
if ptrElem.IsValid() && ptrElem.CanInterface() {
|
||||||
|
return lookupPropertyPathPart(ptrElem.Interface(), part)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package mapping
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLookupPropertyPath(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input interface{}
|
||||||
|
path string
|
||||||
|
output interface{}
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
input: map[string]interface{}{
|
||||||
|
"Type": "a",
|
||||||
|
},
|
||||||
|
path: "Type",
|
||||||
|
output: "a",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: struct {
|
||||||
|
Type string
|
||||||
|
}{
|
||||||
|
Type: "b",
|
||||||
|
},
|
||||||
|
path: "Type",
|
||||||
|
output: "b",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: &struct {
|
||||||
|
Type string
|
||||||
|
}{
|
||||||
|
Type: "b",
|
||||||
|
},
|
||||||
|
path: "Type",
|
||||||
|
output: "b",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
actual := lookupPropertyPath(test.input, test.path)
|
||||||
|
if !reflect.DeepEqual(actual, test.output) {
|
||||||
|
t.Fatalf("expected '%v', got '%v', for path '%s' in %+v", test.output, actual, test.path, test.input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue