Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DjangoJSONEncoder - which handles additional django types #206

Merged
merged 1 commit into from
Jun 23, 2017

Conversation

mzdeb
Copy link
Contributor

@mzdeb mzdeb commented Jun 22, 2017

All supported types: https://docs.djangoproject.com/en/1.11/topics/serialization/#djangojsonencoder

Without this change serialization of:

class Job(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4)

throws exception:

[...]
File "/home/vagrant/env/lib/python3.4/site-packages/ajax_select/fields.py", line 444, in make_plugin_options
    'plugin_options': mark_safe(json.dumps(po)),
  File "/usr/lib/python3.4/json/__init__.py", line 230, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.4/json/encoder.py", line 192, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.4/json/encoder.py", line 250, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.4/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: UUID('998109d4-cf99-42d5-af34-c6b7ba16423a') is not JSON serializable

@crucialfelix
Copy link
Owner

Thanks. Looks useful.

@mzdeb
Copy link
Contributor Author

mzdeb commented Jun 23, 2017

My pleasure! :)

@crucialfelix crucialfelix merged commit f31d866 into crucialfelix:develop Jun 23, 2017
@mzdeb mzdeb deleted the django_json_serializer branch June 23, 2017 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants