@@ -119,7 +119,7 @@ def __init__(
119119 def __getitem__ (self , subfield : str ) -> "Field" :
120120 return cast (Field , self ._params .get ("fields" , {})[subfield ])
121121
122- def _serialize (self , data : Any ) -> Any :
122+ def _serialize (self , data : Any , skip_empty : bool ) -> Any :
123123 return data
124124
125125 def _deserialize (self , data : Any ) -> Any :
@@ -133,10 +133,10 @@ def empty(self) -> Optional[Any]:
133133 return AttrList ([])
134134 return self ._empty ()
135135
136- def serialize (self , data : Any ) -> Any :
136+ def serialize (self , data : Any , skip_empty : bool = True ) -> Any :
137137 if isinstance (data , (list , AttrList , tuple )):
138- return list (map (self ._serialize , cast (Iterable [Any ], data )))
139- return self ._serialize (data )
138+ return list (map (self ._serialize , cast (Iterable [Any ], data , skip_empty )))
139+ return self ._serialize (data , skip_empty )
140140
141141 def deserialize (self , data : Any ) -> Any :
142142 if isinstance (data , (list , AttrList , tuple )):
@@ -186,7 +186,7 @@ def _deserialize(self, data: Any) -> Range["_SupportsComparison"]:
186186 data = {k : self ._core_field .deserialize (v ) for k , v in data .items ()} # type: ignore[union-attr]
187187 return Range (data )
188188
189- def _serialize (self , data : Any ) -> Optional [Dict [str , Any ]]:
189+ def _serialize (self , data : Any , skip_empty : bool ) -> Optional [Dict [str , Any ]]:
190190 if data is None :
191191 return None
192192 if not isinstance (data , collections .abc .Mapping ):
@@ -550,7 +550,7 @@ def _deserialize(self, data: Any) -> "InnerDoc":
550550 return self ._wrap (data )
551551
552552 def _serialize (
553- self , data : Optional [Union [Dict [str , Any ], "InnerDoc" ]]
553+ self , data : Optional [Union [Dict [str , Any ], "InnerDoc" ]], skip_empty : bool
554554 ) -> Optional [Dict [str , Any ]]:
555555 if data is None :
556556 return None
@@ -559,7 +559,7 @@ def _serialize(
559559 if isinstance (data , collections .abc .Mapping ):
560560 return data
561561
562- return data .to_dict ()
562+ return data .to_dict (skip_empty = skip_empty )
563563
564564 def clean (self , data : Any ) -> Any :
565565 data = super ().clean (data )
@@ -768,7 +768,7 @@ def clean(self, data: str) -> str:
768768 def _deserialize (self , data : Any ) -> bytes :
769769 return base64 .b64decode (data )
770770
771- def _serialize (self , data : Any ) -> Optional [str ]:
771+ def _serialize (self , data : Any , skip_empty : bool ) -> Optional [str ]:
772772 if data is None :
773773 return None
774774 return base64 .b64encode (data ).decode ()
@@ -2619,7 +2619,7 @@ def _deserialize(self, data: Any) -> Union["IPv4Address", "IPv6Address"]:
26192619 # the ipaddress library for pypy only accepts unicode.
26202620 return ipaddress .ip_address (unicode (data ))
26212621
2622- def _serialize (self , data : Any ) -> Optional [str ]:
2622+ def _serialize (self , data : Any , skip_empty : bool ) -> Optional [str ]:
26232623 if data is None :
26242624 return None
26252625 return str (data )
@@ -3367,10 +3367,10 @@ def __init__(
33673367 def _deserialize (self , data : Any ) -> "Query" :
33683368 return Q (data ) # type: ignore[no-any-return]
33693369
3370- def _serialize (self , data : Any ) -> Optional [Dict [str , Any ]]:
3370+ def _serialize (self , data : Any , skip_empty : bool ) -> Optional [Dict [str , Any ]]:
33713371 if data is None :
33723372 return None
3373- return data .to_dict () # type: ignore[no-any-return]
3373+ return data .to_dict (skip_empty = skip_empty ) # type: ignore[no-any-return]
33743374
33753375
33763376class Point (Field ):
0 commit comments