[lib] ORJSONResponse can now accept specific encoders

This commit is contained in:
Maxime Alves LIRMM 2020-10-26 15:12:03 +01:00
parent d31efe3cc4
commit 24c68b51f2
1 changed files with 6 additions and 1 deletions

View File

@ -46,9 +46,14 @@ class UnauthorizedResponse(Response):
class ORJSONResponse(JSONResponse):
def __init__(self, content, default=None, **kwargs):
self.default = default
super().__init__(content, **kwargs)
def render(self, content: typ.Any) -> bytes:
return orjson.dumps(content,
option=orjson.OPT_NON_STR_KEYS)
option=orjson.OPT_NON_STR_KEYS,
default=self.default)
class HJSONResponse(ORJSONResponse):