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 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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jul 7, 2014

Comment 1:

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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 7, 2014

Comment 2:

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

@OneOfOne

This comment has been minimized.

Copy link
Contributor Author

@OneOfOne OneOfOne commented Aug 22, 2014

Comment 3:

Any updates about this?
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc 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

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Sep 15, 2014

Comment 5:

Issue #8334 has been merged into this issue.

@NoICE

This comment has been minimized.

Copy link

@NoICE NoICE commented Feb 17, 2016

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

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Feb 17, 2016

@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

This comment has been minimized.

Copy link

@Lagy 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

This comment has been minimized.

Copy link

@flyingmutant flyingmutant commented Feb 26, 2016

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 26, 2016

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

@athap

This comment has been minimized.

Copy link

@athap 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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants
You can’t perform that action at this time.