...
1
2
3 package j2x
4
5 import (
6 "bytes"
7 "fmt"
8 "io/ioutil"
9 "testing"
10 )
11
12 func TestJsonToXml_1(t *testing.T) {
13
14
15 Body := bytes.NewReader([]byte(`[{"some-null-value":"", "a-non-null-value":"bar"}]`))
16
17
18 body, err := ioutil.ReadAll(Body)
19 if err != nil {
20 t.Fatal(err)
21 }
22 fmt.Println(string(body))
23
24
25
26
27 var xmloutput []byte
28
29 xmloutput, err = JsonToXml(body)
30
31
32
33 if err != nil {
34 t.Fatal(err)
35
36
37 }
38 fmt.Println("xmloutput:", string(xmloutput))
39 }
40
41 func TestJsonToXml_2(t *testing.T) {
42
43 Body := bytes.NewReader([]byte(`{"somekey":[{"value":"1st"},{"value":"2nd"}]}`))
44
45
46 body, err := ioutil.ReadAll(Body)
47 if err != nil {
48 t.Fatal(err)
49 }
50 fmt.Println(string(body))
51
52
53
54
55 var xmloutput []byte
56
57 xmloutput, err = JsonToXml(body)
58
59
60
61 if err != nil {
62 t.Fatal(err)
63
64
65 }
66 fmt.Println("xmloutput:", string(xmloutput))
67 }
68
View as plain text