From 7653895dd21ec149db3a9b527d33462e2b59a128 Mon Sep 17 00:00:00 2001 From: zemf4you Date: Thu, 4 Apr 2024 17:34:36 +0700 Subject: [PATCH] refactor(backend): add json_encoders to BaseModel configuration (dev-3.x) This commit introduces a custom JSON encoder for the Default type within the BaseModel configuration of the aiogram package. By specifying how the Default type is serialized, this change ensures consistent representation of Default instances in JSON output, enhancing the predictability of the serialization process. --- aiogram/types/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aiogram/types/base.py b/aiogram/types/base.py index 7ae00524..f97cf03a 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -16,6 +16,9 @@ class TelegramObject(BotContextController, BaseModel): populate_by_name=True, arbitrary_types_allowed=True, defer_build=True, + json_encoders={ + Default: lambda obj: obj.name, + } ) @model_validator(mode="before")