From 4554d91f8917c5322825a04176b6d3b421956773 Mon Sep 17 00:00:00 2001 From: Vasilios Syrakis Date: Wed, 29 Jan 2020 22:32:35 +1100 Subject: [PATCH 1/2] Exclude empty lists from to_dict output --- betterproto/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/betterproto/__init__.py b/betterproto/__init__.py index b426700..b826cc0 100644 --- a/betterproto/__init__.py +++ b/betterproto/__init__.py @@ -728,7 +728,8 @@ class Message(ABC): elif isinstance(v, list): # Convert each item. v = [i.to_dict(casing) for i in v] - output[cased_name] = v + if v: + output[cased_name] = v elif v._serialized_on_wire: output[cased_name] = v.to_dict(casing) elif meta.proto_type == "map": From dbd438e682e15729a23e5404399a07ce7cee5a73 Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Thu, 30 Jan 2020 17:28:22 -0800 Subject: [PATCH 2/2] Update to emit empty lists if asked for defaults --- betterproto/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/betterproto/__init__.py b/betterproto/__init__.py index 0e09de9..8f79270 100644 --- a/betterproto/__init__.py +++ b/betterproto/__init__.py @@ -733,7 +733,7 @@ class Message(ABC): elif isinstance(v, list): # Convert each item. v = [i.to_dict(casing, include_default_values) for i in v] - if v: + if v or include_default_values: output[cased_name] = v else: if v._serialized_on_wire or include_default_values: