From 839b332a2b9d7dcb5536c080e822f85447b615de Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Mon, 26 Oct 2020 23:22:14 +0100 Subject: Use custom JSON encoder for Flask --- api/opendc/util/json.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 api/opendc/util/json.py (limited to 'api/opendc/util') diff --git a/api/opendc/util/json.py b/api/opendc/util/json.py new file mode 100644 index 00000000..2ef4f965 --- /dev/null +++ b/api/opendc/util/json.py @@ -0,0 +1,12 @@ +import flask +from bson.objectid import ObjectId + + +class JSONEncoder(flask.json.JSONEncoder): + """ + A customized JSON encoder to handle unsupported types. + """ + def default(self, o): + if isinstance(o, ObjectId): + return str(o) + return flask.json.JSONEncoder.default(self, o) -- cgit v1.2.3