Skip to content

Commit

Permalink
Adds support to DEFAULT_JSON_ENCODER
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Saavedra committed Oct 28, 2019
1 parent a72e5b2 commit d1b2c67
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/drf_yasg/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
'drf_yasg.inspectors.CoreAPICompatInspector',
],

'DEFAULT_JSON_ENCODER': 'rest_framework.utils.encoders.JSONEncoder',

'EXCLUDED_MEDIA_TYPES': ['html'],

'DEFAULT_INFO': None,
Expand Down Expand Up @@ -88,6 +90,7 @@
'DEFAULT_FIELD_INSPECTORS',
'DEFAULT_FILTER_INSPECTORS',
'DEFAULT_PAGINATOR_INSPECTORS',
'DEFAULT_JSON_ENCODER'
'DEFAULT_INFO',
]

Expand Down
3 changes: 1 addition & 2 deletions src/drf_yasg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
from collections import OrderedDict
from decimal import Decimal

from django.db import models
from django.utils.encoding import force_str
from rest_framework import serializers, status
Expand Down Expand Up @@ -457,7 +456,7 @@ def field_value_to_representation(field, value):

# JSON roundtrip ensures that the value is valid JSON;
# for example, sets and tuples get transformed into lists
return json.loads(json.dumps(value, cls=encoders.JSONEncoder))
return json.loads(json.dumps(value, cls=swagger_settings.DEFAULT_JSON_ENCODER))


def get_field_default(field):
Expand Down

0 comments on commit d1b2c67

Please sign in to comment.