forked from p15670423/monkey
Changed default flask json encoder so we could encode objects with custom fields, like field of type ObjectId
This commit is contained in:
parent
96f3052dc2
commit
5a6a68fde0
|
@ -8,6 +8,7 @@ from werkzeug.exceptions import NotFound
|
|||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||
from common.common_consts.api_url_consts import T1216_PBA_FILE_DOWNLOAD_PATH
|
||||
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
||||
from monkey_island.cc.custom_json_encoder import CustomJSONEncoder
|
||||
from monkey_island.cc.database import database, mongo
|
||||
from monkey_island.cc.resources.attack.attack_config import AttackConfiguration
|
||||
from monkey_island.cc.resources.attack.attack_report import AttackReport
|
||||
|
@ -85,6 +86,8 @@ def init_app_config(app, mongo_url):
|
|||
# configuration. See https://flask.palletsprojects.com/en/1.1.x/config/#JSON_SORT_KEYS.
|
||||
app.config['JSON_SORT_KEYS'] = False
|
||||
|
||||
app.json_encoder = CustomJSONEncoder
|
||||
|
||||
|
||||
def init_app_services(app):
|
||||
init_jwt(app)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
from bson import ObjectId
|
||||
from flask.json import JSONEncoder
|
||||
|
||||
|
||||
class CustomJSONEncoder(JSONEncoder):
|
||||
|
||||
def default(self, obj):
|
||||
try:
|
||||
if isinstance(obj, ObjectId):
|
||||
return obj.__str__()
|
||||
except TypeError:
|
||||
pass
|
||||
return JSONEncoder.default(self, obj)
|
Loading…
Reference in New Issue