Skip to content

Commit

Permalink
use non-deprecated way of changing JSON encoder (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
briantist authored Dec 24, 2022
1 parent 52306a4 commit fac2e53
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions galactory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
# (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

from .api import bp as api
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()

Expand All @@ -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)
Expand Down

0 comments on commit fac2e53

Please sign in to comment.