python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.16k stars 335 forks source link

Custom encoding class error when ujson installed #395

Open organisciak opened 2 years ago

organisciak commented 2 years ago

I just ran into an opaque error due to the fact that flask-restx imports dumps from either ujson or json, depending on whether the former is installed.

The issue is with custom JSON encoding classes, e.g.

app.config["RESTX_JSON"] = {"cls": CustomEncoder}

json.dumps supports the cls arg but ujson.dumps does not, so having ujson installed on a system will cause the code to crash.

The only way to address it is to uninstall ujson, I think. I wonder if either a more descriptive error message or a way to force the default json.dumps would help avoid this issue? Or perhaps it's worth considering a more current 'fast JSON' library that aligns more closely with the API of the default one?