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