提交 ddf52d01 编写于 作者: P Peter Krempa

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.
上级 81069ae3
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册