diff --git a/chapter11/annotations/jsonxml/jsonxml.go b/chapter11/annotations/jsonxml/jsonxml.go new file mode 100644 index 0000000..3940da5 --- /dev/null +++ b/chapter11/annotations/jsonxml/jsonxml.go @@ -0,0 +1,22 @@ +package main + +import ( + "encoding/json" + "encoding/xml" + "os" +) + +type Person struct { + FirstName string `json:"first" xml:"firstName,attr"` + LastName string `json:"last" xml:"lastName"` +} + +func main() { + p := &Person{FirstName: "Inigo", LastName: "Montoya"} + j, _ := json.MarshalIndent(p, "", " ") + os.Stdout.Write(j) + println() + + x, _ := xml.MarshalIndent(p, "", " ") + os.Stdout.Write(x) +}