From 36f0946e2d7ccc7b9736eaac5ebd4852d070eab7 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Feb 2023 21:08:40 -0500 Subject: fix flask json deprecation --- lib/utils/json.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/utils/json.py') 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__()") -- cgit v1.2.3