Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
json: fix option alias support (#18801)
- Loading branch information
Showing
2 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
|
||
struct Test { | ||
optional_alias ?MyAlias // primitive | ||
optional_struct ?MyAlias2 // complex | ||
} | ||
|
||
struct Complex { | ||
a int = 3 | ||
} | ||
|
||
type MyAlias = int | ||
type MyAlias2 = Complex | ||
|
||
fn test_empty() { | ||
test := Test{} | ||
encoded := json.encode(test) | ||
assert dump(encoded) == '{}' | ||
assert json.decode(Test, '{}')! == test | ||
} | ||
|
||
fn test_value() { | ||
test := Test{ | ||
optional_alias: 1 | ||
} | ||
encoded := json.encode(test) | ||
assert dump(encoded) == '{"optional_alias":1}' | ||
assert json.decode(Test, '{"optional_alias":1}')! == test | ||
} | ||
|
||
fn test_value_2() { | ||
test := Test{ | ||
optional_alias: 1 | ||
optional_struct: Complex{ | ||
a: 1 | ||
} | ||
} | ||
encoded := json.encode(test) | ||
assert dump(encoded) == '{"optional_alias":1,"optional_struct":{"a":1}}' | ||
assert json.decode(Test, '{"optional_alias":1,"optional_struct":{"a":1}}')! == test | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters