Utilizing response encoders and decoders
Flask framework supports the built Python json
module by default. The built-in encoders, dumps()
, and loads()
, are found in the flask.json
module. In the Managing the requests and responses section, the add_login()
endpoint function uses the flask.json.loads()
to de-serialize and transform the request.data
into a JSONable dictionary. Meanwhile, the flask.json.dumps()
provided the Response
class with a JSONable object for some JSON response output, as previously highlighted in the list_all_login()
endpoint.
But any application can override these default encoding and decoding processes to solve some custom requirements. Customizing an appropriate JSON provider by sub-classing Flaskās JSONProvider
, found in the flask.json.provider
, can allow the overriding of these JSON processes. The following is a custom implementation of a JSONProvider
with some modifications to the dumps()
and loads()
algorithms:
from flask.json.provider import...