json: use @[required] to disallow parsing nulls (#23218)

This commit is contained in:
Carlos Esquerdo Bernat 2024-12-22 09:12:58 +01:00 committed by GitHub
parent 1ca902fcc4
commit 63fff1dcd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 64 additions and 11 deletions

View file

@ -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