nonebot2/nonebot/utils.py
2020-08-10 13:06:02 +08:00

17 lines
336 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import dataclasses
from nonebot.typing import overrides
class DataclassEncoder(json.JSONEncoder):
@overrides(json.JSONEncoder)
def default(self, o):
if dataclasses.is_dataclass(o):
return dataclasses.asdict(o)
return super().default(o)