mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
json: use @[required]
to disallow parsing nulls (#23218)
This commit is contained in:
parent
1ca902fcc4
commit
63fff1dcd4
3 changed files with 64 additions and 11 deletions
|
@ -4692,7 +4692,7 @@ struct User {
|
|||
last_name string @[json: lastName]
|
||||
}
|
||||
|
||||
data := '{ "name": "Frodo", "lastName": "Baggins", "age": 25 }'
|
||||
data := '{ "name": "Frodo", "lastName": "Baggins", "age": 25, "nullable": null }'
|
||||
user := json.decode(User, data) or {
|
||||
eprintln('Failed to decode json, error: ${err}')
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue