<s> from django . utils . encoding import force_text <EOL> from bson import ObjectId <EOL> from rest_framework . utils . encoders import JSONEncoder <EOL> from rest_framework . renderers import JSONRenderer <EOL> class MongoDBJSONEncoder ( JSONEncoder ) : <EOL> def default ( self , obj ) : <EOL> if isinstance ( obj , ObjectId ) : <EOL> return force_text ( obj ) <EOL> return super ( MongoDBJSONEncoder , self ) . default ( obj ) <EOL> class MongoDBJSONRenderer ( JSONRenderer ) : <EOL> encoder_class = MongoDBJSONEncoder </s>
