diff --git a/src/drf_yasg/app_settings.py b/src/drf_yasg/app_settings.py index 6592d34b..5be07731 100644 --- a/src/drf_yasg/app_settings.py +++ b/src/drf_yasg/app_settings.py @@ -27,6 +27,8 @@ 'drf_yasg.inspectors.CoreAPICompatInspector', ], + 'DEFAULT_JSON_ENCODER': 'rest_framework.utils.encoders.JSONEncoder', + 'EXCLUDED_MEDIA_TYPES': ['html'], 'DEFAULT_INFO': None, @@ -88,6 +90,7 @@ 'DEFAULT_FIELD_INSPECTORS', 'DEFAULT_FILTER_INSPECTORS', 'DEFAULT_PAGINATOR_INSPECTORS', + 'DEFAULT_JSON_ENCODER' 'DEFAULT_INFO', ] diff --git a/src/drf_yasg/utils.py b/src/drf_yasg/utils.py index 3784e4b6..527358ad 100644 --- a/src/drf_yasg/utils.py +++ b/src/drf_yasg/utils.py @@ -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 @@ -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):