diff --git a/ceilometer/api/v1/app.py b/ceilometer/api/v1/app.py index 76d64892..0ff6edfd 100644 --- a/ceilometer/api/v1/app.py +++ b/ceilometer/api/v1/app.py @@ -18,7 +18,6 @@ """Set up the API server application instance.""" import flask -import flask.helpers from oslo.config import cfg from ceilometer.api import acl @@ -26,10 +25,11 @@ from ceilometer.api.v1 import blueprint as v1_blueprint from ceilometer.openstack.common import jsonutils from ceilometer import storage -# Replace the json module used by flask with the one from -# openstack.common so we can take advantage of the fact that it knows -# how to serialize more complex objects. -flask.helpers.json = jsonutils + +class JSONEncoder(flask.json.JSONEncoder): + @staticmethod + def default(o): + return jsonutils.to_primitive(o) def make_app(conf, enable_acl=True, attach_storage=True, @@ -37,6 +37,8 @@ def make_app(conf, enable_acl=True, attach_storage=True, app = flask.Flask('ceilometer.api') app.register_blueprint(v1_blueprint.blueprint, url_prefix='/v1') + app.json_encoder = JSONEncoder + try: with open(sources_file, "r") as f: sources = jsonutils.load(f) diff --git a/requirements.txt b/requirements.txt index c08e2d2f..6a3edec5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ netaddr pymongo>=2.4 eventlet>=0.13.0 anyjson>=0.3.3 -Flask==0.9 +Flask>=0.10,<1.0 pecan>=0.2.0 stevedore>=0.10 msgpack-python