generics.ListCreateAPIView-MongoEngine: Object of type ObjectId is not JSON serializable #9080
Unanswered
481460Prasanna
asked this question in
Potential Issue
Replies: 1 comment
-
django REST framework do not support mongo engine by default |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
While using the django restframework generics.ListCreateAPIView, I am getting below issue for a simple mongodb document, I am getting below error.
TypeError: Object of type ObjectId is not JSON serializable
I am using below versions,
django-rest-framework-mongoengine 3.4.1
djangorestframework 3.14.0
Django 3.2.6
Please help and guide further.
Here is the exception stacktrace for reference.
Traceback (most recent call last):
File "C:\venvs\ttap\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\venvs\ttap\lib\site-packages\django\core\handlers\base.py", line 204, in get_response
response = response.render()
File "C:\venvs\ttap\lib\site-packages\django\template\response.py", line 105, in render
self.content = self.rendered_content
File "C:\venvs\ttap\lib\site-packages\rest_framework\response.py", line 70, in rendered_content
ret = renderer.render(self.data, accepted_media_type, context)
File "C:\venvs\ttap\lib\site-packages\rest_framework\renderers.py", line 99, in render
ret = json.dumps(
File "C:\venvs\ttap\lib\site-packages\rest_framework\utils\json.py", line 25, in dumps
return json.dumps(*args, **kwargs)
File "C:\tz_apps\mnc\lib\json_init.py", line 234, in dumps
return cls(
File "C:\tz_apps\mnc\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\tz_apps\mnc\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\venvs\ttap\lib\site-packages\rest_framework\utils\encoders.py", line 67, in default
return super().default(obj)
File "C:\tz_apps\mnc\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type ObjectId is not JSON serializable
Thanks in Advance!
Beta Was this translation helpful? Give feedback.
All reactions