Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Empty key name when decoding map from struct with only omitempty flag #238

@semrekkers

Description

@semrekkers

If a structtag only contains ,omitempty when decoding a map from a struct, the keyName is overwritten by an empty string. I can't find whether this is defined behavior. If not, I have a PR ready to fix this.

Example:

type Struct struct {
	Username string `mapstructure:",omitempty"`
}

s := Struct{
	Username: "Joe",
}
var m map[string]interface{}
mapstructure.Decode(s, &m)

// Output: map[:Joe]
// Expected output: map[Username:Joe]
fmt.Printf("%+v", m)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions