Skip to content

Commit 336cf95

Browse files
author
artem
committed
subclass JsonEncoder from django base encoder class
1 parent 74c34d5 commit 336cf95

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

api_commons/common.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
import collections
2525
import logging
2626
import sys
27-
from json import JSONEncoder
2827
from typing import Union
29-
from uuid import UUID
3028

3129
from django.core.exceptions import ObjectDoesNotExist
30+
from django.core.serializers.json import DjangoJSONEncoder
3231
from django.http import HttpRequest
3332
from django.http import HttpResponse
3433
from rest_framework import status as HttpStatus
@@ -146,12 +145,10 @@ def forbidden(cls):
146145
)
147146

148147

149-
class JsonEncoder(JSONEncoder):
148+
class JsonEncoder(DjangoJSONEncoder):
150149
def default(self, o):
151150
if isinstance(o, BaseDto):
152151
return o.to_dict()
153-
if isinstance(o, UUID):
154-
return str(o)
155152
return super().default(o)
156153

157154

0 commit comments

Comments
 (0)