{"action":"closed","issue":{"url":"https://api.github.com/repos/umutbozkurt/django-rest-framework-mongoengine/issues/82","labels_url":"https://api.github.com/repos/umutbozkurt/django-rest-framework-mongoengine/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/umutbozkurt/django-rest-framework-mongoengine/issues/82/comments","events_url":"https://api.github.com/repos/umutbozkurt/django-rest-framework-mongoengine/issues/82/events","html_url":"https://github.com/umutbozkurt/django-rest-framework-mongoengine/issues/82","id":59744773,"number":82,"title":"ObjectIdField should raise ValidationError","user":{"login":"qwiglydee","id":285128,"avatar_url":"https://avatars.githubusercontent.com/u/285128?v=3","gravatar_id":"","url":"https://api.github.com/users/qwiglydee","html_url":"https://github.com/qwiglydee","followers_url":"https://api.github.com/users/qwiglydee/followers","following_url":"https://api.github.com/users/qwiglydee/following{/other_user}","gists_url":"https://api.github.com/users/qwiglydee/gists{/gist_id}","starred_url":"https://api.github.com/users/qwiglydee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qwiglydee/subscriptions","organizations_url":"https://api.github.com/users/qwiglydee/orgs","repos_url":"https://api.github.com/users/qwiglydee/repos","events_url":"https://api.github.com/users/qwiglydee/events{/privacy}","received_events_url":"https://api.github.com/users/qwiglydee/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-04T03:18:09Z","updated_at":"2015-10-13T15:57:15Z","closed_at":"2015-10-13T15:57:15Z","body":"Just like all other fields do when input is inconvertable.\r\nSurrounding frameworks would know nothing about bson.errors\r\n\r\n```\r\nclass ObjectIdField(fields.Field):\r\n    type_label = 'ObjectIdField'\r\n\r\n    def to_representation(self, value):\r\n        return smart_str(value)\r\n\r\n    def to_internal_value(self, data):\r\n        try:\r\n            return ObjectId(data)\r\n        except bson.errors.InvalidId as e:\r\n            raise ValidationError(e)\r\n```"}}