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

Missing pointer value "0" while encoding struct #34

Closed
mifanich opened this issue Apr 9, 2018 · 6 comments · Fixed by #35
Closed

Missing pointer value "0" while encoding struct #34

mifanich opened this issue Apr 9, 2018 · 6 comments · Fixed by #35
Assignees
Labels

Comments

@mifanich
Copy link

mifanich commented Apr 9, 2018

type T struct {
X *uint8 form:"x,omitempty"
}

func main() {
tx := uint8(0)
x := T{&tx}
encoder := form.NewEncoder()
values, _ := encoder.Encode(x)
fmt.Println(values) // blank map
}

If I try to set value to 0, encoder ignores this field

@deankarn
Copy link
Contributor

deankarn commented Apr 9, 2018

Thanks @mifanich for reporting, I suspect it's a bug in the omitempty logic thinking 0 is the default value after dereference, hopefully just an order of operations issue.

@mifanich
Copy link
Author

mifanich commented Apr 9, 2018

@joeybloggs When do you plan to fix it

@deankarn deankarn self-assigned this Apr 9, 2018
@deankarn
Copy link
Contributor

deankarn commented Apr 9, 2018

As soon as I find the time, hopefully, this evening after work.

if you need it sooner, PR's are welcome :)

@mifanich
Copy link
Author

mifanich commented Apr 9, 2018

thank you very much

@deankarn
Copy link
Contributor

@mifanich this should be fixed in v3.1.3 release, please let me know :)

@mifanich
Copy link
Author

It works now. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants