-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Update
ORJSONResponse
to support non str
keys and serializing N…
…umpy arrays (#3892) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
173b891
commit 7250c19
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from fastapi import FastAPI | ||
from fastapi.responses import ORJSONResponse | ||
from fastapi.testclient import TestClient | ||
from sqlalchemy.sql.elements import quoted_name | ||
|
||
app = FastAPI(default_response_class=ORJSONResponse) | ||
|
||
|
||
@app.get("/orjson_non_str_keys") | ||
def get_orjson_non_str_keys(): | ||
key = quoted_name(value="msg", quote=False) | ||
return {key: "Hello World", 1: 1} | ||
|
||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_orjson_non_str_keys(): | ||
with client: | ||
response = client.get("/orjson_non_str_keys") | ||
assert response.json() == {"msg": "Hello World", "1": 1} |