1
0
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:
Felipe Pena
2023-04-13 03:17:40 -03:00
committed by GitHub
parent 3d99f1f2c2
commit 524f7c3ead
2 changed files with 27 additions and 4 deletions

View 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
}