diff --git a/django_jsonform/forms/fields.py b/django_jsonform/forms/fields.py index 65983f5..5846195 100644 --- a/django_jsonform/forms/fields.py +++ b/django_jsonform/forms/fields.py @@ -1,9 +1,9 @@ import json -from uuid import UUID import django from django.db import models from django.conf import settings from django.core.exceptions import ImproperlyConfigured, ValidationError +from django.core.serializers.json import DjangoJSONEncoder from django_jsonform.utils import _get_django_version django_major, django_minor = _get_django_version() @@ -75,13 +75,6 @@ def add_error(self, error_map): self.widget.add_error(error_map) -class UUIDCompatibleEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, UUID): - return str(obj) - return json.JSONEncoder.default(self, obj) - - class ArrayFormField(SimpleArrayField): def __init__(self, base_field, **kwargs): if hasattr(SimpleArrayField, 'mock_field'): @@ -103,7 +96,7 @@ def __init__(self, base_field, **kwargs): def prepare_value(self, value): if isinstance(value, list): - return json.dumps(value, cls=UUIDCompatibleEncoder) + return json.dumps(value, cls=DjangoJSONEncoder) return value def to_python(self, value):