v / vlib / json / tests / json_encode_recursive_ptr_test.v
19 lines · 16 sloc · 513 bytes · 8ebbacecd60366ac4ba68aa35f9b0e7a0e56ff61
Raw
1import json
2
3struct PostTag {
4 id string
5 parent ?&PostTag
6 visibility string
7 created_at string @[json: 'createdAt']
8 metadata string @[raw]
9}
10
11fn test_main() {
12 new_post_tag := &PostTag{}
13 assert json.encode(new_post_tag) == '{"id":"","visibility":"","createdAt":"","metadata":""}'
14
15 new_post_tag2 := PostTag{
16 parent: new_post_tag
17 }
18 assert json.encode(new_post_tag2) == '{"id":"","parent":{"id":"","visibility":"","createdAt":"","metadata":""},"visibility":"","createdAt":"","metadata":""}'
19}
20