diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2023-02-26 17:35:22 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-26 17:35:22 -0500 |
| commit | 97f711b9807b422329f26b6db7a77fb102e0664d (patch) | |
| tree | 6051a865838b3df6fbb558e7bbe1c6a2a78c6e1c /lib/utils/json.py | |
| parent | ed0ab5a44d08068e9f02bc689edc03899995e74b (diff) | |
| parent | 36f0946e2d7ccc7b9736eaac5ebd4852d070eab7 (diff) | |
Merge pull request #2088 from inkstitch/lexelby/fix-preferences-set-default
fix preferences "set default" buttons
Diffstat (limited to 'lib/utils/json.py')
| -rw-r--r-- | lib/utils/json.py | 12 |
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__()") |
