From 08d6d7c2a9583a803f0917b2114620e56b73d0cf Mon Sep 17 00:00:00 2001 From: Anton Lavrik Date: Sat, 29 Sep 2012 18:57:17 -0500 Subject: [PATCH] (piqi,ocaml,erlang) json-omit-null-fields now works for repeated fields as well The json-omit-null-fields setting, when true, leads to non-existent repeated fields being omitted from JSON output (in addition to missing optinal fields). Before this change, they were included and had [] as a value. --- piqilib/piqobj_to_json.ml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/piqilib/piqobj_to_json.ml b/piqilib/piqobj_to_json.ml index 7cd680a5..b9450c09 100644 --- a/piqilib/piqobj_to_json.ml +++ b/piqilib/piqobj_to_json.ml @@ -105,9 +105,12 @@ and gen_field fields t = ) | `repeated -> let fields = List.find_all pred fields in - let json_fields = List.map (fun f -> gen_obj (some_of f.obj)) fields in - let res = make_named name (`List json_fields) in - [res] + if fields = [] && !omit_null_fields + then [] + else + let json_fields = List.map (fun f -> gen_obj (some_of f.obj)) fields in + let res = make_named name (`List json_fields) in + [res] and gen_variant x =