diff --git a/django_jsonform/forms/fields.py b/django_jsonform/forms/fields.py index 1f2909e..b92667e 100644 --- a/django_jsonform/forms/fields.py +++ b/django_jsonform/forms/fields.py @@ -74,6 +74,13 @@ 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'): @@ -95,7 +102,7 @@ def __init__(self, base_field, **kwargs): def prepare_value(self, value): if isinstance(value, list): - return json.dumps(value) + return json.dumps(value, cls=UUIDCompatibleEncoder) return value def to_python(self, value): @@ -120,4 +127,4 @@ def get_schema(self): if self.min_items: schema['min_items'] = self.min_items - return schema \ No newline at end of file + return schema