mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Handle UUID objects in JSONEncoder. Closes #2433.
This commit is contained in:
parent
b3a0a2794b
commit
da1db34a36
|
@ -12,6 +12,7 @@ import datetime
|
|||
import decimal
|
||||
import types
|
||||
import json
|
||||
import uuid
|
||||
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
|
@ -45,6 +46,8 @@ class JSONEncoder(json.JSONEncoder):
|
|||
elif isinstance(obj, decimal.Decimal):
|
||||
# Serializers will coerce decimals to strings by default.
|
||||
return float(obj)
|
||||
elif isinstance(obj, uuid.UUID):
|
||||
return six.text_type(obj)
|
||||
elif isinstance(obj, QuerySet):
|
||||
return tuple(obj)
|
||||
elif hasattr(obj, 'tolist'):
|
||||
|
|
Loading…
Reference in New Issue
Block a user