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

encoding/xml: cannot Unmarshal empty non-string nodes even with omitempty. #8333

Closed
OneOfOne opened this issue Jul 7, 2014 · 11 comments
Closed
Milestone

Comments

@OneOfOne
Copy link
Contributor

OneOfOne commented Jul 7, 2014

Calling xml.Unmarshal will die with `error: strconv.ParseFloat: parsing "":
invalid syntax` on an empty node unless you change it's type to string, even with
`emptyempty` set.

Example program: http://play.golang.org/p/VSk6TsuEPN

Discussion:
http://stackoverflow.com/questions/24602155/unmarshalling-optional-float64-field-returns-error-on-go/24602310#24602310

I realize one could use the UnmarshalXML interface, however I believe this is a bug in
the xml package and it shouldn't try to use strconv on an empty node when omitempty is
set.
@gopherbot
Copy link

Comment 1:

CL https://golang.org/cl/109500043 mentions this issue.

@ianlancetaylor
Copy link
Contributor

Comment 2:

Labels changed: added repo-main, release-go1.4.

@OneOfOne
Copy link
Contributor Author

Comment 3:

Any updates about this?

@rsc
Copy link
Contributor

rsc commented Sep 15, 2014

Comment 4:

omitempty is about marshalling, not unmarshalling.
If you need to accept an empty string, make it a string field and call
strconv.ParseFloat yourself.

Status changed to WorkingAsIntended.

@rsc
Copy link
Contributor

rsc commented Sep 15, 2014

Comment 5:

Issue #8334 has been merged into this issue.

@daliborfilus
Copy link

Why is this issue closed? This is NOT working as it should.

@bradfitz
Copy link
Contributor

@noice, we don't have discussions on closed issues. Please bring this question to the mailing list. See https://golang.org/wiki/Questions

Thanks!

@Lagy
Copy link

Lagy commented Feb 26, 2016

Great. So the issue cannot be reopened? Because nothing was solved and I am still hanging on this...
DAMN !!!
@bradfitz, please can you give me some helpfull solution?

@flyingmutant
Copy link
Contributor

@Lagy please take a look at #13417 which is open.

@ianlancetaylor
Copy link
Contributor

@Lagy Brad already pointed you at https://golang.org/wiki/Questions . Please start there. Thanks.

@athap
Copy link

athap commented Apr 7, 2016

An easy way to solve this issue of empty self closing tags or empty tag is to use
https://github.com/guregu/null package.

I am not a big fan of using packages for small stuff but this package have saved a lot of time for me

Here is how I am using this
http://play.golang.org/p/xGKeIUM6NO

Full credit to guregu/null

@golang golang locked and limited conversation to collaborators Apr 8, 2017
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants