-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (43 loc) · 778 Bytes
/
Copy pathmain.go
File metadata and controls
52 lines (43 loc) · 778 Bytes
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
package main
import (
"encoding/json"
"fmt"
"github.com/amzn/ion-go/ion"
)
type Foo struct {
A string
B string
}
type Zop struct {
Value Foo
Annotations []ion.SymbolToken `ion:",annotations"`
}
type Bar struct {
Barr Zop
}
func main() {
a := Bar{
Barr: Zop{
Value: Foo{
A: "ABC",
B: "DEF",
},
Annotations: []ion.SymbolToken{ion.NewSymbolTokenFromString("ABC")},
},
}
res, err := ion.MarshalText(a)
if err != nil {
panic(err)
}
var b Bar
err = ion.Unmarshal(res, &b)
if err != nil {
panic(err)
}
// These should print the same output as we have gone from
// go struct -> ION -> go struct
e, _ := json.Marshal(a)
fmt.Printf("Encoded: %s\n", string(e))
d, _ := json.Marshal(b)
fmt.Printf("Decoded: %s\n", string(d))
}