@@ -735,9 +735,7 @@ def serialize(self, values):
735735 rval = {}
736736 for k in values :
737737 v = values [k ]
738- # Continue to serialize NULL values in "raw" map attributes for backwards compatibility.
739- # This special case behavior for "raw" attribtues should be removed in the future.
740- if not self .is_raw () and v is None :
738+ if self ._should_skip (v ):
741739 continue
742740 attr_class = self ._get_serialize_class (k , v )
743741 if attr_class is None :
@@ -751,7 +749,12 @@ def serialize(self, values):
751749 attr = self ._get_attributes ().get (k )
752750 attr_name = attr .attr_name if attr else k
753751
754- rval [attr_name ] = {attr_key : attr_class .serialize (v )}
752+ serialized = attr_class .serialize (v )
753+ if self ._should_skip (serialized ):
754+ # Check after we serialize in case the serialized value is null
755+ continue
756+
757+ rval [attr_name ] = {attr_key : serialized }
755758
756759 return rval
757760
@@ -788,6 +791,11 @@ def as_dict(self):
788791 result [key ] = value .as_dict () if isinstance (value , MapAttribute ) else value
789792 return result
790793
794+ def _should_skip (self , value ):
795+ # Continue to serialize NULL values in "raw" map attributes for backwards compatibility.
796+ # This special case behavior for "raw" attribtues should be removed in the future.
797+ return not self .is_raw () and value is None
798+
791799 @classmethod
792800 def _get_serialize_class (cls , key , value ):
793801 if not cls .is_raw ():
0 commit comments