use aliases in all keys list to enable proper Unmarshaling
diff --git a/viper.go b/viper.go
index 00049ec..a056e61 100644
--- a/viper.go
+++ b/viper.go
@@ -1149,6 +1149,10 @@
m[strings.ToLower(key)] = struct{}{}
}
+ for key, _ := range v.aliases {
+ m[strings.ToLower(key)] = struct{}{}
+ }
+
a := []string{}
for x, _ := range m {
a = append(a, x)
diff --git a/viper_test.go b/viper_test.go
index fcb9c4e..ebde5ba 100644
--- a/viper_test.go
+++ b/viper_test.go
@@ -838,3 +838,28 @@
t.Fatalf("fu != \"bar\", = %s", fu)
}
}
+
+func TestUnmarshalingWithAliases(t *testing.T) {
+ SetDefault("Id", 1)
+ Set("name", "Steve")
+ Set("lastname", "Owen")
+
+ RegisterAlias("UserID","Id")
+ RegisterAlias("Firstname","name")
+ RegisterAlias("Surname","lastname")
+
+ type config struct {
+ Id int
+ FirstName string
+ Surname string
+ }
+
+ var C config
+
+ err := Unmarshal(&C)
+ if err != nil {
+ t.Fatalf("unable to decode into struct, %v", err)
+ }
+
+ assert.Equal(t, &C, &config{Id: 1, FirstName: "Steve", Surname: "Owen"})
+}
\ No newline at end of file