@@ -33,7 +33,12 @@ class Config:
3333 orm_mode = True
3434
3535 def dict (
36- self , * , by_alias : bool = True , exclude_defaults : bool = True , ** kwargs
36+ self ,
37+ * ,
38+ by_alias : bool = True ,
39+ exclude_defaults : bool = False ,
40+ exclude_none : bool = True ,
41+ ** kwargs
3742 ) -> dict :
3843 """
3944 Serialize the model using custom settings.
@@ -42,8 +47,11 @@ def dict(
4247 by_alias (bool, optional): Whether to create serialized field names by
4348 their alias (default `True`).
4449 exclude_defaults (bool, optional): Whether to exclude fields that are equal
45- to their default value from being serialized (default `True`).
46- **kwargs:
50+ to their default value from being serialized (default `False`).
51+ exclude_none (bool, optional): Whether to exclude keys with `None` values
52+ entirely (default `True`).
53+ **kwargs: Further keyword arguments are passed to the pydantic super method
54+ `.dict`.
4755
4856 Returns:
4957 dict: The serialized model as a (nested) dictionary.
@@ -53,7 +61,10 @@ def dict(
5361
5462 """
5563 return super ().dict (
56- by_alias = by_alias , exclude_defaults = exclude_defaults , ** kwargs
64+ by_alias = by_alias ,
65+ exclude_defaults = exclude_defaults ,
66+ exclude_none = exclude_none ,
67+ ** kwargs
5768 )
5869
5970 def json (
0 commit comments