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

How to handle key conflicts when using mapstructure:",squash" ? #356

Open
dangquyitt opened this issue Jun 13, 2024 · 1 comment
Open

How to handle key conflicts when using mapstructure:",squash" ? #356

dangquyitt opened this issue Jun 13, 2024 · 1 comment

Comments

@dangquyitt
Copy link

dangquyitt commented Jun 13, 2024

type Order struct {
	Id string
}

type User struct {
	Id    string
	Order Order `mapstructure:",squash"`
}

result := map[string]interface{}{}
mapstructure.Decode(User{
	Id: "userId",
	Order: Order{
		Id: "orderId",
	},
}, &result)

log.Println(result)
Output: map[Id:orderId]
Expected: map[Id:userId Order.Id:orderId]
@ashmeenkaur
Copy link

+1, we also need this feature

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants