Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnmarshalKey: Using "y" variable in yml stays empty #1146

Closed
maltegrosse opened this issue May 31, 2021 · 3 comments
Closed

UnmarshalKey: Using "y" variable in yml stays empty #1146

maltegrosse opened this issue May 31, 2021 · 3 comments
Labels
kind/support Support requests for using the project resolution/invalid This doesn't seem right

Comments

@maltegrosse
Copy link

maltegrosse commented May 31, 2021

Expected behavior (what you expected to happen):
By using a yaml file with an array and 3 fields, e.g.

---
genres:
  - genre: soul
    x: 703
    y: 15128
  - genre: pop
    x: 1150
    y: 13682

and creating a struct

type Genre struct {
	Genre string `mapstructure:"genre"`
	Y int `mapstructure:"y"`
	X int `mapstructure:"x"`

}
var Genres []Genre
viper.UnmarshalKey("genres", &Genres)

should fill the structs with string genre,int x and y.

Actual behavior (what actually happened):
Field Y stays empty. X is filled with a value.

Workaround:

Rename yaml field to any other variable, e.g. mm and use in struct: Y int `mapstructure:"mm"`

Environment:

  • Viper version: v1.7.1
  • Config source: file
  • File format: YAML
@maltegrosse maltegrosse added the kind/bug Something isn't working label May 31, 2021
@github-actions
Copy link

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news,
either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

@xwjdsh
Copy link

xwjdsh commented Jul 22, 2021

go-yaml/yaml#740
In YAML 1.1, scalars like y and Y are resolved as booleans, change to this,

---
genres:
  - genre: soul
    x: 703
    'y': 15128
  - genre: pop
    x: 1150
    'y': 13682

@sagikazarmark
Copy link
Collaborator

Thanks @xwjdsh !

Closing as it's working as expected.

@sagikazarmark sagikazarmark added kind/support Support requests for using the project resolution/invalid This doesn't seem right and removed kind/bug Something isn't working labels Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Support requests for using the project resolution/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants