mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix json encoding of structs with option fields (skip the fields with a value of none) (#16916)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import x.json2
|
||||
|
||||
struct Foo {
|
||||
name string
|
||||
@@ -11,10 +12,18 @@ fn test_json_encode_struct_with_option_field() {
|
||||
}
|
||||
ret1 := json.encode(f1)
|
||||
println(ret1)
|
||||
assert ret1 == '{"name":"hello","num":null}'
|
||||
assert ret1 == '{"name":"hello"}'
|
||||
|
||||
ret2 := json2.encode(f1)
|
||||
println(ret2)
|
||||
assert ret2 == '{"name":"hello"}'
|
||||
|
||||
f2 := Foo{'hello', 22}
|
||||
ret2 := json.encode(f2)
|
||||
println(ret2)
|
||||
assert ret2 == '{"name":"hello","num":22}'
|
||||
ret3 := json.encode(f2)
|
||||
println(ret3)
|
||||
assert ret3 == '{"name":"hello","num":22}'
|
||||
|
||||
ret4 := json2.encode(f2)
|
||||
println(ret4)
|
||||
assert ret4 == '{"name":"hello","num":22}'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user