New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Json encoder customization #199
Json encoder customization #199
Conversation
👍 |
@@ -124,7 +124,7 @@ def wrapper(*args, **kwargs): | |||
logger.debug('Endpoint returned an empty response (204)', extra={'url': url, 'mimetype': self.mimetype}) | |||
return '', 204, headers | |||
|
|||
data = json.dumps(data, indent=2, cls=JSONEncoder) | |||
data = json.dumps(data, indent=2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is the custom JSON encoder now used by json.dumps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same question, but somehow it's working on the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This json.dumps
come from flask
namespace (http://flask.pocoo.org/docs/0.10/api/#flask.json.dumps) which changes the behaviour to use as encoder the class referenced by the flask app attribute json_encoder
. That is the expected behaviour while using JSON encoders with flask. So you can personalize the encoder changing the app.json_encoder
.
References:
http://flask.pocoo.org/snippets/119/
http://flask.pocoo.org/docs/0.10/api/#flask.Flask.json_encoder
Can we merge that? |
@rafaelcaricio if you rebase the branch, yes. |
26d7d51
to
8509d68
Compare
8509d68
to
7cd60a9
Compare
@jmcs Didn't realize it got conflicts. Should be good now. 👍 |
Fixes #196.
Connexion should remain as must compatible as possible with usual Flask applications. This PR adds back the support of developers to customize the json_encoder in Connexion applications exactly as in pure Flask apps.
Changes proposed in this pull request:
JSONEncoder
internally in Connexion.flask.Flask.json_encoder
for customization of encoding. This makes possible for users of Connexion to override the encoder they wanna use.