diff --git a/fastapi/encoders.py b/fastapi/encoders.py index 451ea0760..c416abbcb 100644 --- a/fastapi/encoders.py +++ b/fastapi/encoders.py @@ -240,7 +240,7 @@ def jsonable_encoder( custom_encoder=encoders, sqlalchemy_safe=sqlalchemy_safe, ) - if dataclasses.is_dataclass(obj): + if dataclasses.is_dataclass(type(obj)): obj_dict = dataclasses.asdict(obj) return jsonable_encoder( obj_dict, diff --git a/fastapi/routing.py b/fastapi/routing.py index 8ea4bb219..c0d9c821a 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -118,7 +118,7 @@ def _prepare_response_content( ) for k, v in res.items() } - elif dataclasses.is_dataclass(res): + elif dataclasses.is_dataclass(type(res)): return dataclasses.asdict(res) return res