From f636f2624d6b09d0bd7da78ccdbadcfdffe8618c Mon Sep 17 00:00:00 2001 From: Brian Scholer <1260690+briantist@users.noreply.github.com> Date: Sat, 24 Dec 2022 14:03:39 -0500 Subject: [PATCH] use non-deprecated way of changing JSON encoder --- galactory/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/galactory/__init__.py b/galactory/__init__.py index 8d58aef..14dd897 100644 --- a/galactory/__init__.py +++ b/galactory/__init__.py @@ -2,10 +2,11 @@ # (c) 2022 Brian Scholer (@briantist) import logging +import typing as t from datetime import datetime from flask import Flask, request -from flask.json import JSONEncoder +from flask.json.provider import DefaultJSONProvider from configargparse import ArgParser, ArgumentError, Action from artifactory import ArtifactoryPath @@ -13,8 +14,10 @@ from .download import bp as download from .health import bp as health -class DateTimeIsoFormatJSONEncoder(JSONEncoder): - def default(self, o): + +class DateTimeIsoFormatJSONProvider(DefaultJSONProvider): + @staticmethod + def default(o: t.Any) -> t.Any: if isinstance(o, datetime): return o.isoformat() @@ -23,7 +26,7 @@ def default(self, o): def create_app(**config): app = Flask(__name__) - app.json_encoder = DateTimeIsoFormatJSONEncoder + app.json = DateTimeIsoFormatJSONProvider(app) app.config.update(**config) app.register_blueprint(health) app.register_blueprint(api)