Will not panic on interface type in struct. (#62)
* Will not panic on interface type in struct.
This commit is contained in:
parent
f23af605df
commit
c7685df069
@ -550,6 +550,11 @@ func (s *Struct) nested(val reflect.Value) interface{} {
|
|||||||
// TODO(arslan): should this be optional?
|
// TODO(arslan): should this be optional?
|
||||||
finalVal = val.Interface()
|
finalVal = val.Interface()
|
||||||
case reflect.Slice, reflect.Array:
|
case reflect.Slice, reflect.Array:
|
||||||
|
if val.Type().Kind() == reflect.Interface {
|
||||||
|
finalVal = val.Interface()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(arslan): should this be optional?
|
// TODO(arslan): should this be optional?
|
||||||
// do not iterate of non struct types, just pass the value. Ie: []int,
|
// do not iterate of non struct types, just pass the value. Ie: []int,
|
||||||
// []string, co... We only iterate further if it's a struct.
|
// []string, co... We only iterate further if it's a struct.
|
||||||
|
|||||||
@ -1362,3 +1362,17 @@ func TestNonStringerTagWithStringOption(t *testing.T) {
|
|||||||
t.Errorf("Value for field Animal should not exist")
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user