summaryrefslogtreecommitdiff
path: root/lib/utils/json.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/json.py')
-rw-r--r--lib/utils/json.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/utils/json.py b/lib/utils/json.py
index 63b3cfb5..22107c48 100644
--- a/lib/utils/json.py
+++ b/lib/utils/json.py
@@ -3,10 +3,15 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-from flask.json import JSONEncoder
+from flask.json.provider import DefaultJSONProvider
+from ..exceptions import InkstitchException
-class InkStitchJSONEncoder(JSONEncoder):
+class InkstitchJSONException(InkstitchException):
+ pass
+
+
+class InkStitchJSONProvider(DefaultJSONProvider):
"""JSON encoder class that runs __json__ on an object if available.
The __json__ method should return a JSON-compatible representation of the
@@ -17,4 +22,5 @@ class InkStitchJSONEncoder(JSONEncoder):
try:
return obj.__json__()
except AttributeError:
- return JSONEncoder.default(self, obj)
+ raise InkstitchJSONException(
+ f"Object of type {obj.__class__.__name__} cannot be serialized to JSON because it does not implement __json__()")