Will not panic on interface type in struct. (#62)

* Will not panic on interface type in struct.
This commit is contained in:
davrux 2016-06-15 18:13:29 +02:00 committed by Fatih Arslan
parent f23af605df
commit c7685df069
2 changed files with 19 additions and 0 deletions

View File

@ -550,6 +550,11 @@ func (s *Struct) nested(val reflect.Value) interface{} {
// TODO(arslan): should this be optional?
finalVal = val.Interface()
case reflect.Slice, reflect.Array:
if val.Type().Kind() == reflect.Interface {
finalVal = val.Interface()
break
}
// TODO(arslan): should this be optional?
// do not iterate of non struct types, just pass the value. Ie: []int,
// []string, co... We only iterate further if it's a struct.

View File

@ -1362,3 +1362,17 @@ func TestNonStringerTagWithStringOption(t *testing.T) {
t.Errorf("Value for field Animal should not exist")
}
}
func TestMap_InterfaceValue(t *testing.T) {
type TestStruct struct {
A interface{}
}
expected := []byte("test value")
a := TestStruct{A: expected}
s := Map(a)
if !reflect.DeepEqual(s["A"], expected) {
t.Errorf("Value does not match expected: %q != %q", s["A"], expected)
}
}