I am implementing similar logic in Flask-Security - so stole some code :-)
The code:
class MongoEngineJSONProvider(superclass):
"""A JSON Provider update for Flask 2.2.0+"""
@staticmethod
def default(obj):
"""Extend JSONProvider default static method, with Mongo objects."""
if isinstance(
obj,
(BaseDocument, QuerySet, CommandCursor, DBRef, ObjectId),
):
return _convert_mongo_objects(obj)
return super().default(obj)
I don't think is quite right - using super() for static methods doesn't work - you need to do something like:
return super(MongoEngineJSONProvider, MongoEngineJSONProvider).default(obj)
I am implementing similar logic in Flask-Security - so stole some code :-)
The code:
I don't think is quite right - using super() for static methods doesn't work - you need to do something like:
return super(MongoEngineJSONProvider, MongoEngineJSONProvider).default(obj)