Created
June 20, 2013 18:28
-
-
Save anonymous/5825288 to your computer and use it in GitHub Desktop.
Unable to unmarshal int with spaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/xml" | |
"fmt" | |
) | |
type MyType struct { | |
XMLName xml.Name `bson:"-" xml:"response"` | |
Result int `bson:"result" xml:"result"` | |
} | |
func main() { | |
var payload string | |
payload = ` | |
<response> | |
<result>1</result> | |
</response> | |
` | |
var mt MyType | |
xml.Unmarshal([]byte(payload), &mt) | |
// This prints: {XMLName:{Space: Local:response} Result:1} | |
fmt.Printf("mt was %+v\n", mt) | |
// NOTE: result has spaces | |
payload = ` | |
<response> | |
<result> 1 </result> | |
</response> | |
` | |
var newmt MyType | |
xml.Unmarshal([]byte(payload), &newmt) | |
// This prints: {XMLName:{Space: Local:response} Result:0} | |
fmt.Printf("newmt was %+v\n", newmt) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment