mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
json: fix [omitempty]
with string (#17813)
This commit is contained in:
parent
57aa4def62
commit
cd6cc65ece
2 changed files with 51 additions and 19 deletions
25
vlib/json/json_omitempty_test.v
Normal file
25
vlib/json/json_omitempty_test.v
Normal file
|
@ -0,0 +1,25 @@
|
|||
import json
|
||||
|
||||
pub struct MyStruct {
|
||||
pub mut:
|
||||
code int
|
||||
message string
|
||||
data string [omitempty]
|
||||
data2 ?string [omitempty]
|
||||
}
|
||||
|
||||
fn test_simple() {
|
||||
obj := MyStruct{
|
||||
code: 1
|
||||
message: 'yes'
|
||||
data2: 'a'
|
||||
}
|
||||
assert dump(json.encode(obj)) == '{"code":1,"message":"yes","data2":"a"}'
|
||||
}
|
||||
|
||||
fn test_none() {
|
||||
obj := MyStruct{
|
||||
code: 1
|
||||
}
|
||||
assert dump(json.encode(obj)) == '{"code":1,"message":""}'
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue