Support for Python dataclasses
in default JSON Encoder
#8890
-
Python Unfortunately, Python's Does it make sense to add generic support for Would you be open to a PR to add this feature? A simple: +import dataclasses
[...]
class JSONEncoder(json.JSONEncoder):
[...]
def default(self, obj):
[...]
+ if dataclasses.is_dataclass(obj):
+ obj = dataclasses.asdict(obj) seems to do the trick for my use case, though there might be plenty of complexities I'm not thinking of, as a DRF noob. I see that currently: REQUIRED_PYTHON = (3, 6) so that speaks at least against my naive approach, even if the feature sounds good in general. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
drf is an extension of django, so we have to take how django is using dataclass right now |
Beta Was this translation helpful? Give feedback.
Django don't see incorporating typing in existing codes yet. but if you can do some tweaks in DRF, which will make life of end developers without making big breaking changes to DRF, contributions are welcome.