I'm using django-uuidfield together with django-rest-framework to develop a RESTful API.
Whenever I try to use the UUIDField, Django throws me this error:
TypeError at (...)
UUID('a00fef915e284f6d9d9af8b0500234b7') is not JSON serializable
I believe the UUIDField lacks a method which can serialize it to JSON using python's JSON encoder and decoder.
Here's the stack trace:
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
137. response = response.render()
File "/usr/local/lib/python2.7/dist-packages/django/template/response.py" in render
103. self.content = self.rendered_content
File "/usr/local/lib/python2.7/dist-packages/rest_framework/response.py" in rendered_content
63. ret = renderer.render(self.data, media_type, context)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/renderers.py" in render
606. context = self.get_context(data, accepted_media_type, renderer_context)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/renderers.py" in get_context
556. raw_data_post_form = self.get_raw_data_form(view, 'POST', request)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/renderers.py" in get_raw_data_form
506. content = renderer.render(serializer.data, accepted, context)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/renderers.py" in render
87. indent=indent, ensure_ascii=self.ensure_ascii
File "/usr/lib/python2.7/json/__init__.py" in dumps
250. sort_keys=sort_keys, **kw).encode(obj)
File "/usr/lib/python2.7/json/encoder.py" in encode
209. chunks = list(chunks)
File "/usr/lib/python2.7/json/encoder.py" in _iterencode
434. for chunk in _iterencode_dict(o, _current_indent_level):
File "/usr/lib/python2.7/json/encoder.py" in _iterencode_dict
408. for chunk in chunks:
File "/usr/lib/python2.7/json/encoder.py" in _iterencode
442. o = _default(o)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/utils/encoders.py" in default
58. return super(JSONEncoder, self).default(o)
File "/usr/lib/python2.7/json/encoder.py" in default
184. raise TypeError(repr(o) + " is not JSON serializable")
Exception Type: TypeError at /api/Participants/
Exception Value: UUID('a00fef915e284f6d9d9af8b0500234b7') is not JSON serializable