mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: fix json with option struct (#17942)
This commit is contained in:
23
vlib/json/json_option_struct_test.v
Normal file
23
vlib/json/json_option_struct_test.v
Normal file
@ -0,0 +1,23 @@
|
||||
import json
|
||||
|
||||
pub struct SomeStruct {
|
||||
pub mut:
|
||||
test ?string
|
||||
}
|
||||
|
||||
pub struct MyStruct {
|
||||
pub mut:
|
||||
result ?SomeStruct
|
||||
id string
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
a := MyStruct{
|
||||
id: 'some id'
|
||||
result: SomeStruct{}
|
||||
}
|
||||
encoded_string := json.encode(a)
|
||||
assert encoded_string == '{"result":{},"id":"some id"}'
|
||||
test := json.decode(MyStruct, encoded_string)!
|
||||
assert test == a
|
||||
}
|
Reference in New Issue
Block a user