drf_orjson_renderer
drf_orjson_renderer copied to clipboard
Removes DjangoNumpyJSONEncoder (breaking change)
As suggested in https://github.com/brianjbuck/drf_orjson_renderer/pull/24, DjangoNumpyJSONEncoder
should no longer be necessary when using orjson 3.3 or newer. This fixes an issue when this package is used with numpy 2.0, which has removed np.float_
. However, since we'd be removing existing functionality, I think this has to be a breaking change. I did not update the version, but I guess this should probably mean going to 2.0.0
.
@DanyilVoloshchuk, That would be a better solution than the original one proposed. You really shouldn't need it however since v3.3
orjson
supports both numpy versions out of the box. That encoder was written beforeorjson
supportednumpy
and only exists for some backwards compatibility before everyone upgradedorjson
versions.My preferred solution would be to remove the
DjangoNumpyJSONEncoder
entirely and have everyone migrate away from using that encoder. The docs could probably be more clear that developers should be using theorjson
options instead:REST_FRAMEWORK = { "ORJSON_RENDERER_OPTIONS": ( orjson.OPT_SERIALIZE_NUMPY, ), }