Skip to content

Commit da1db34

Browse files
committed
Handle UUID objects in JSONEncoder. Closes #2433.
1 parent b3a0a27 commit da1db34

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

rest_framework/utils/encoders.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import decimal
1313
import types
1414
import json
15+
import uuid
1516

1617

1718
class JSONEncoder(json.JSONEncoder):
@@ -45,6 +46,8 @@ def default(self, obj):
4546
elif isinstance(obj, decimal.Decimal):
4647
# Serializers will coerce decimals to strings by default.
4748
return float(obj)
49+
elif isinstance(obj, uuid.UUID):
50+
return six.text_type(obj)
4851
elif isinstance(obj, QuerySet):
4952
return tuple(obj)
5053
elif hasattr(obj, 'tolist'):

0 commit comments

Comments
 (0)