When initializing Eve one can specify a custom made json encoder, like it is specified in the documentation here, you can make something like:
from eve.io.base import BaseJSONEncoder
class CustomJSONEncoder(BaseJSONEncoder):
...
app = Eve(settings=settings, json_encoder=CustomJSONEncoder)
What I expected is that, internally, the result would be:
flask.json_encoder == CustomJSONEncoder
but what I found in the flaskapp Eve code is that:
self.data.json_encoder_class = CustomJSONEncoder
which is accessible later on with app.data.json_encoder_class
. This causes that if you use any flask add-on which relies on the encoder, you will not have the custom encodings you expect.
The straighforward solution may be:
app = Eve(settings=settings, json_encoder=CustomJSONEncoder)
app.json_encoder = CustomJSONEncoder
but I wonder:
- Why Eve does not do it itself?
- Is there any reason to avoid changing Flask's default JSON encoder?
- Does Eve makes something 'extra the
data.json_encoder_class
? - Should this be documented?