v2 / vlib / json / tests / json_option_struct_test.v
23 lines · 20 sloc · 370 bytes · 8ebbacecd60366ac4ba68aa35f9b0e7a0e56ff61
Raw
1import json
2
3pub struct SomeStruct {
4pub mut:
5 test ?string
6}
7
8pub struct MyStruct {
9pub mut:
10 result ?SomeStruct
11 id string
12}
13
14fn test_main() {
15 a := MyStruct{
16 id: 'some id'
17 result: SomeStruct{}
18 }
19 encoded_string := json.encode(a)
20 assert encoded_string == '{"result":{},"id":"some id"}'
21 test := json.decode(MyStruct, encoded_string)!
22 assert test == a
23}
24