(obj)
| 55 | |
| 56 | |
| 57 | def default(obj): |
| 58 | if hasattr(obj, "__json__") and six.callable(obj.__json__): |
| 59 | return obj.__json__() |
| 60 | elif isinstance(obj, bytes): |
| 61 | # TODO: We should update the code which passes bytes to pass unicode to avoid this |
| 62 | # conversion here |
| 63 | return obj.decode("utf-8") |
| 64 | elif isinstance(obj, bson.ObjectId): |
| 65 | return str(obj) |
| 66 | raise TypeError |
| 67 | |
| 68 | |
| 69 | def json_encode_native_json(obj, indent=4, sort_keys=False): |