| 1 | import json |
| 2 | |
| 3 | struct Bar { |
| 4 | name ?string @[json_null] |
| 5 | } |
| 6 | |
| 7 | struct Foo { |
| 8 | name ?string @[json_null] |
| 9 | age ?int @[json_null] |
| 10 | text ?string |
| 11 | other ?Bar |
| 12 | other2 ?Bar @[json_null] |
| 13 | } |
| 14 | |
| 15 | fn test_main() { |
| 16 | assert json.encode(Foo{}) == '{"name":null,"age":null,"other2":null}' |
| 17 | assert json.encode(Foo{ name: '' }) == '{"name":"","age":null,"other2":null}' |
| 18 | assert json.encode(Foo{ age: 10 }) == '{"name":null,"age":10,"other2":null}' |
| 19 | assert json.encode(Foo{ |
| 20 | age: 10 |
| 21 | other2: Bar{ |
| 22 | name: none |
| 23 | } |
| 24 | }) == '{"name":null,"age":10,"other2":{"name":null}}' |
| 25 | assert json.decode(Foo, json.encode(Foo{}))! == Foo{} |
| 26 | } |
| 27 | |