add test for decoding direct struct
diff --git a/mapstructure.go b/mapstructure.go
index d48ac95..c5e33be 100644
--- a/mapstructure.go
+++ b/mapstructure.go
@@ -554,6 +554,8 @@
func (d *Decoder) decodeStruct(name string, data interface{}, val reflect.Value) error {
dataVal := reflect.Indirect(reflect.ValueOf(data))
+ // If the type of the value to write to and the data match directly,
+ // then we just set it directly instead of recursing into the structure.
if dataVal.Type() == val.Type() {
val.Set(dataVal)
return nil
diff --git a/mapstructure_test.go b/mapstructure_test.go
index 0c9a31f..1c24e3f 100644
--- a/mapstructure_test.go
+++ b/mapstructure_test.go
@@ -335,6 +335,26 @@
}
}
+func TestDecode_StructMatch(t *testing.T) {
+ t.Parallel()
+
+ input := map[string]interface{}{
+ "vbar": Basic{
+ Vstring: "foo",
+ },
+ }
+
+ var result Nested
+ err := Decode(input, &result)
+ if err != nil {
+ t.Fatalf("got an err: %s", err.Error())
+ }
+
+ if result.Vbar.Vstring != "foo" {
+ t.Errorf("bad: %#v", result)
+ }
+}
+
func TestDecode_TypeConversion(t *testing.T) {
input := map[string]interface{}{
"IntToFloat": 42,