Browse Source

Merge ef0dcd2f11 into 8032e21418

pull/12452/merge
0xsaif 3 days ago
committed by GitHub
parent
commit
b4993df565
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 31
      fastapi/encoders.py

31
fastapi/encoders.py

@ -297,22 +297,20 @@ def jsonable_encoder(
encoded_dict[encoded_key] = encoded_value encoded_dict[encoded_key] = encoded_value
return encoded_dict return encoded_dict
if isinstance(obj, (list, set, frozenset, GeneratorType, tuple, deque)): if isinstance(obj, (list, set, frozenset, GeneratorType, tuple, deque)):
encoded_list = [] return [
for item in obj: jsonable_encoder(
encoded_list.append( item,
jsonable_encoder( include=include,
item, exclude=exclude,
include=include, by_alias=by_alias,
exclude=exclude, exclude_unset=exclude_unset,
by_alias=by_alias, exclude_defaults=exclude_defaults,
exclude_unset=exclude_unset, exclude_none=exclude_none,
exclude_defaults=exclude_defaults, custom_encoder=custom_encoder,
exclude_none=exclude_none, sqlalchemy_safe=sqlalchemy_safe,
custom_encoder=custom_encoder,
sqlalchemy_safe=sqlalchemy_safe,
)
) )
return encoded_list for item in obj
]
if type(obj) in ENCODERS_BY_TYPE: if type(obj) in ENCODERS_BY_TYPE:
return ENCODERS_BY_TYPE[type(obj)](obj) return ENCODERS_BY_TYPE[type(obj)](obj)
@ -323,8 +321,7 @@ def jsonable_encoder(
try: try:
data = dict(obj) data = dict(obj)
except Exception as e: except Exception as e:
errors: List[Exception] = [] errors: List[Exception] = [e]
errors.append(e)
try: try:
data = vars(obj) data = vars(obj)
except Exception as e: except Exception as e:

Loading…
Cancel
Save