From ca472716dbb2976d2ec3d54a8a898a4747ee9bf0 Mon Sep 17 00:00:00 2001 From: izzy lyseggen Date: Thu, 16 Dec 2021 16:41:09 +0000 Subject: [PATCH] feat(serialisation): allow null values --- specklepy/objects/base.py | 3 +++ specklepy/serialization/base_object_serializer.py | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/specklepy/objects/base.py b/specklepy/objects/base.py index 1f0883a..d280bee 100644 --- a/specklepy/objects/base.py +++ b/specklepy/objects/base.py @@ -252,6 +252,9 @@ class Base(_RegisteringBase): if t is None: return value + if value is None: + return None + if t.__module__ == "typing": origin = getattr(t, "__origin__") t = ( diff --git a/specklepy/serialization/base_object_serializer.py b/specklepy/serialization/base_object_serializer.py index 9ab45dd..24516a0 100644 --- a/specklepy/serialization/base_object_serializer.py +++ b/specklepy/serialization/base_object_serializer.py @@ -60,8 +60,13 @@ class BaseObjectSerializer: chunkable = False detach = False - # skip nulls or props marked to be ignored with "__" or "_" - if value is None or prop.startswith(("__", "_")): + # skip props marked to be ignored with "__" or "_" + if prop.startswith(("__", "_")): + continue + + # allow serialisation of nulls + if not value: + object_builder[prop] = value continue # don't prepopulate id as this will mess up hashing