diff --git a/marshal.go b/marshal.go index b6e8ec1..3e92a57 100644 --- a/marshal.go +++ b/marshal.go @@ -470,7 +470,12 @@ func (d *Decoder) valueFromTree(mtype reflect.Type, tval *Tree) (reflect.Value, opts := tomlOptions(mtypef, an) if opts.include { baseKey := opts.name - keysToTry := []string{baseKey, strings.ToLower(baseKey), strings.ToTitle(baseKey)} + keysToTry := []string{ + baseKey, + strings.ToLower(baseKey), + strings.ToTitle(baseKey), + strings.ToLower(string(baseKey[0])) + baseKey[1:], + } for _, key := range keysToTry { exists := tval.Has(key) if !exists { diff --git a/marshal_test.go b/marshal_test.go index 8d00322..9c401b3 100644 --- a/marshal_test.go +++ b/marshal_test.go @@ -1120,3 +1120,20 @@ func TestUnmarshalBadDuration(t *testing.T) { t.Fatalf("unexpected error: %s", err) } } + +var testCamelCaseKeyToml = []byte(`fooBar = 10`) + +func TestUnmarshalCamelCaseKey(t *testing.T) { + var x struct { + FooBar int + B int + } + + if err := Unmarshal(testCamelCaseKeyToml, &x); err != nil { + t.Fatal(err) + } + + if x.FooBar != 10 { + t.Fatal("Did not set camelCase'd key") + } +}