json: teach json builder "conditional" object fields
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Nov 2018 21:26:21 +0000 (22:26 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 28 Nov 2018 07:38:55 +0000 (08:38 +0100)
commit319a4f27c477cbc63decdc510b7ca698a7be44f4
tree3b7810fb51304b549612d61a3e9f9929bd15b52f
parent2de622531400f45f60d8182d41fceb1d7335e5e8
json: teach json builder "conditional" object fields

Quite often when we generate objects some fields should only be
generated in some conditions. Let's add high-level support for that.
Matching the existing JSON_BUILD_PAIR() this adds
JSON_BUILD_PAIR_CONDITIONAL() which is very similar, but takes an
additional parameter: a boolean condition. If "true" this acts like
JSON_BUILD_PAIR(), but if false then the whole pair is suppressed.

This sounds simply, but requires a tiny bit of complexity: when complex
sub-variants are used in fields, then we also need to suppress them.
src/shared/json.c
src/shared/json.h
src/test/test-json.c