...
1 package x2j
2
3 import (
4 "encoding/json"
5 "fmt"
6 "testing"
7 )
8
9 func TestGoofy(t *testing.T) {
10 var doc = `<xml><tag one="1" pi="3.1415962535" bool="true"/><tagJR key="value"/></xml>`
11 type goofy struct {
12 S string
13 Sp *string
14 }
15 g := new(goofy)
16 g.S = "Now is the time for"
17 tmp := "all good men to come to"
18 g.Sp = &tmp
19
20 m, err := DocToMap(doc)
21 if err != nil {
22 fmt.Println("err:",err.Error())
23 return
24 }
25
26 m["goofyVal"] = interface{}(g)
27 m["byteVal"] = interface{}([]byte(`the aid of their country`))
28 m["nilVal"] = interface{}(nil)
29
30 fmt.Println("\nTestGoofy ... MapToDoc:",m)
31 var v []byte
32 v,err = json.Marshal(m)
33 if err != nil {
34 fmt.Println("err:",err.Error())
35 }
36 fmt.Println("v:",string(v))
37
38 type goofier struct {
39 G *goofy
40 B []byte
41 N *string
42 }
43 gg := new(goofier)
44 gg.G = g
45 gg.B = []byte(`the tree of freedom must periodically be`)
46 gg.N = nil
47 m["goofierVal"] = interface{}(gg)
48
49 fmt.Println("\nTestGoofier ... MapToDoc:",m)
50 v,err = json.Marshal(m)
51 if err != nil {
52 fmt.Println("err:",err.Error())
53 }
54 fmt.Println("v:",string(v))
55 }
56
57
View as plain text