mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: skip via the "-" attribute
This commit is contained in:
parent
638f0f69ed
commit
b9f5cc830b
@ -60,6 +60,7 @@ mut:
|
||||
total_comments int
|
||||
file_name string [skip]
|
||||
comments []Comment [skip]
|
||||
skip_field string [json: '-']
|
||||
}
|
||||
|
||||
fn test_skip_fields_should_be_initialised_by_json_decode() {
|
||||
@ -70,6 +71,15 @@ fn test_skip_fields_should_be_initialised_by_json_decode() {
|
||||
assert task.comments == []
|
||||
}
|
||||
|
||||
fn test_skip_should_be_ignored() {
|
||||
data := '{"total_comments": 55, "id": 123, "skip_field": "foo"}'
|
||||
mut task := json.decode(Task, data)!
|
||||
assert task.id == 123
|
||||
assert task.total_comments == 55
|
||||
assert task.comments == []
|
||||
assert task.skip_field == ''
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
struct DbConfig {
|
||||
|
@ -527,7 +527,11 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
|
||||
for attr in field.attrs {
|
||||
match attr.name {
|
||||
'json' {
|
||||
name = attr.arg
|
||||
if attr.arg == '-' {
|
||||
is_skip = true
|
||||
} else {
|
||||
name = attr.arg
|
||||
}
|
||||
}
|
||||
'skip' {
|
||||
is_skip = true
|
||||
|
Loading…
Reference in New Issue
Block a user