mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
util: json: Add option to skip adding a JSON object if it is NULL
Add a new option specifier that will optionally add a JSON key=value pair containing a nested object if the added object isn't NULL.
This commit is contained in:
parent
81069ae3f5
commit
ddf52d01f8
@ -99,6 +99,7 @@ struct _virJSONParser {
|
||||
* n: json null value
|
||||
*
|
||||
* a: json object, must be non-NULL
|
||||
* A: json object, omitted if NULL
|
||||
*
|
||||
* The value corresponds to the selected type.
|
||||
*
|
||||
@ -230,10 +231,14 @@ virJSONValueObjectCreateVArgs(virJSONValuePtr *obj, va_list args)
|
||||
rc = virJSONValueObjectAppendNull(jargs, key);
|
||||
} break;
|
||||
|
||||
case 'A':
|
||||
case 'a': {
|
||||
virJSONValuePtr val = va_arg(args, virJSONValuePtr);
|
||||
|
||||
if (!val) {
|
||||
if (type == 'A')
|
||||
continue;
|
||||
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("argument key '%s' must not have null value"),
|
||||
key);
|
||||
|
Loading…
Reference in New Issue
Block a user