From cb2b4e3522cb7f426ba5ad3e68deb9e6ccc581ec Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 28 Apr 2020 12:34:05 -0400 Subject: electron simulator (#531) --- lib/utils/json.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/utils/json.py (limited to 'lib/utils/json.py') diff --git a/lib/utils/json.py b/lib/utils/json.py new file mode 100644 index 00000000..c670a46b --- /dev/null +++ b/lib/utils/json.py @@ -0,0 +1,15 @@ +from flask.json import JSONEncoder + + +class InkStitchJSONEncoder(JSONEncoder): + """JSON encoder class that runs __json__ on an object if available. + + The __json__ method should return a JSON-compatible representation of the + object. + """ + + def default(self, obj): + try: + return obj.__json__() + except AttributeError: + return JSONEncoder.default(self, obj) -- cgit v1.2.3