Skip to content

Instantly share code, notes, and snippets.

@deepakjois
Last active December 18, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepakjois/5797150 to your computer and use it in GitHub Desktop.
Save deepakjois/5797150 to your computer and use it in GitHub Desktop.
Is there a bug in the YAML decoder?
package main
import (
"fmt"
"encoding/json"
"launchpad.net/goyaml"
)
type Bar struct {
Name string
}
type Foo struct {
Address string
Bar
}
func main() {
var g Foo
var h Bar
err := goyaml.Unmarshal([]byte("---\nname: Deepak"),&g)
fmt.Println(g) // Output: { {}} (Does not work)
fmt.Println(err) // <nil>
json.Unmarshal([]byte("{ \"Name\" : \"Deepak\" }"),&g)
fmt.Println(g) // Output: { {Deepak}} (Works)
goyaml.Unmarshal([]byte("---\nname: Deepak"),&h)
fmt.Println(h) // Output: {Deepak} (Works)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment